fix unable create perf event when run samples/schedule/schedtimes.kp

clear the idmap nr in idmap_free.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
unshare common files between userspace and runtime

Now usespace and runtime have completely seperated build
dependency, no common files shared.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
remove __KERNEL__ ifdef in ktap.h

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
code cleanup

remove some unused functions in userspace/util.c
rename ktapio.c to ktap_io.c

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
rename eventdef.c parse_events.c

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
fix typo in Makefile

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
improve performance for table resize

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
use lastfree field to improve userspace table set operation

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
tiny header file cleanup

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
move dump_function into dump.c

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
make table to be pre-allocated and disallow table resize

New function for pre-allocate table entries:
	 table.new(narr, nrec)

For ptable, use:
	ptable(narr, nrec)

If no parameter given, then ktapvm pre-allocate default size:
	default narr: 128
	default nrec: 2048

if table entries exceed the default number, ktapvm will exit
with overflow error.

If default value is not enough for script, user must to enlarge
the vaule by above two functions.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
fix compile error

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
Check whether ring buffer already is allocated

We need to check whether ring buffer is allocated before
trying to free it.

I tried to add ktap to my board, but I ran into the following calltrace,
this patch is to fix it.

ktap: cannot lookup ftrace_find_event in kallsyms
Cannot open file /sys/kernel/debug/ktap/trace_pipe_1643
Unable to handle kernel paging request for data at address 0x00000010
Faulting instruction address: 0xc0000000004933dc
Oops: Kernel access of bad area, sig: 11 [#1]
PREEMPT SMP NR_CPUS=24 LTT NESTING LEVEL : 0
T4240 QDS
Modules linked in: ktapvm(O) [last unloaded: ktapvm]
NIP: c0000000004933dc LR: c0000000001125b0 CTR: c000000000112540
REGS: c0000005f576f5f0 TRAP: 0300   Tainted: G           O  (3.4.43-WR5.0.1.0_standard)
MSR: 0000000080029000 <CE,EE,ME>  CR: 24000444  XER: 00000000
SOFTE: 1
DEAR: 0000000000000010, ESR: 0000000000000000
TASK = c0000005f4725200[1643] 'ktap' THREAD: c0000005f576c000 CPU: 2
GPR00: 0000000000000000 c0000005f576f870 c000000000ce4328 0000000000000010
GPR04: 0000000000000000 0000000000000000 0000000024000424 c00000000000a12c
GPR08: 0000000000000000 0000000000000018 0000000000000000 0000000000000010
GPR12: 80000000003be4b0 c00000000fffa800 0000000000000000 0000000000000000
GPR16: 0000000000000000 0000000000000000 00000000100c7c48 00000000101179e8
GPR20: 00000000100f0000 c000000000b77bc0 0000000000000000 0000000000000000
GPR24: 0000000000000003 0000000000000000 0000000000000000 ffffffffffffffff
GPR28: 0000000000000010 c000000000cf3a9c c000000000c2c1a8 0000000000000000
NIP [c0000000004933dc] .find_next_bit+0x7c/0x110
LR [c0000000001125b0] .ring_buffer_free+0x70/0xd0
Call Trace:
[c0000005f576f870] [c000000000112580] .ring_buffer_free+0x40/0xd0 (unreliable)
[c0000005f576f910] [80000000003b9440] .kp_transport_exit+0x20/0x50 [ktapvm]
[c0000005f576f990] [80000000003bd628] .kp_final_exit+0x408/0x450 [ktapvm]
[c0000005f576fa60] [80000000003bddd8] .kp_newstate+0x728/0x770 [ktapvm]
[c0000005f576fb70] [80000000003bde6c] .ktap_main+0x4c/0x190 [ktapvm]
[c0000005f576fc10] [80000000003be06c] .compat_ktap_ioctl+0xbc/0xe0 [ktapvm]
[c0000005f576fcf0] [c000000000215428] .compat_sys_ioctl+0x388/0x1ae0
[c0000005f576fe30] [c000000000000598] syscall_exit+0x0/0x60
Instruction dump:
60000000 e80b0000 396b0008 2fa00000 409e0038 3929ffc0 38a50040 79200665
4082ffe4 2fa90000 7ca42b78 419e0034 <e80b0000> 21690040 3940ffff 7d4b5c36
---[ end trace f3e31e8a981317f6 ]---

Signed-off-by: Yang Wei <w90p710@gmail.com>
Using a correct symbol name to look up its address for PPC64

For PPC64, the PPC64 ABI introduces function descriptor, it
is a three doubleword data structure. Its first doubleword
contains the address of the entry point of the function.

The value of the symbol with the same name as the function
is the address of function descriptor, Conversely, Symbol names
with a dot(.) prefix are real entry point addresses.

Signed-off-by: Yang Wei <w90p710@gmail.com>
Remake ktap whenever flags are changed

Save build flags into KTAP-FLAGS, and remake when it is different
from the last time.
change table allocation from kmalloc to vmalloc

This will make table handle large number entries.
(all memory needed by table is allocated in table initization)

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
simplify table_histogram based on kp_tab_sort function

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
Support ffi.new syntax

It parses ffi.new and does necessary interpretation.

Example:
ffi.new("int[5]") indicates to allocate space which could contain 5
ints, and is translated to
base + i	: ffi
base + i+1	: new
base + i+2	: csymbol id for "int" type
base + i+3	: 5
base + i+4	: call

Signed-off-by: Qingping Hou <qingping.hou@gmail.com>
Support ffi.new logic in vm

It would allocate the space to contain the array, and treat the return
value as ktap_cdata in pointer type.

Signed-off-by: Yicheng Qin <qycqycqycqycqyc@gmail.com>
Signed-off-by: Qingping Hou <qingping.hou@gmail.com>
New tests for ffi.new

Signed-off-by: Yicheng Qin <qycqycqycqycqyc@gmail.com>
Signed-off-by: Qingping Hou <qingping.hou@gmail.com>