Revert "only mainthread can call table pairs and histogram"

Sometime we have to call histogram or pairs in timer context,
so allow non-mainthread to do that.

This is still a temp solution, because using pairs and histogram
in non-mainthread have a little unsafe, find a more safe way
to fix it.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
update comments of perf overflow callback

make comments to be more accurate.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
kill unused function event_regstr

register dump functionality in ktap should be implemented
by some kind of FFI support(implement in future), don't dump
the register vaule one by one manually.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
add skip and max_entries option arguments into print_backtrace()/backtrace()

Normally skip and max_entries both set to 10 when dump stack,
but sometimes stack entries exceed 10, or skip 10 entries is
not enough, so allow user dump stack with specific skip and
max_entries.

print_backtrace (skip, max_entries)
backtrace (skip, max_entries)

If user don't add skip or max_entries arguments, use 10 defaultly.

Note the max number of max_entries is 100.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
skip 12 stack entries in dumpstack() for stack_profile.kp

Skip 12 stack entries to hide some timer interrupt function,
make stack dump more accurate.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
fix error handling in kp_lib_printf function

add missed preempt_enable_notrace.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
make kp_init_state a little faster

Use memset to init all stack value to nil, instead of
for-loop many times, memset would be more efficient.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
disallow stack growing in ktap

Set a stack size limit for ktap, if thread exceed the limit,
ktapvm will report "stack overflow".

The default stack size is 120, enlarge this value if script
need more stack.

Make this value to be configurable in future.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
add test/stack_overflow.kp

This testcase is purpose for stack overflow checking.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
support dump more instructions

Below instructions can be dump now by "ktap -b *.kp"
1. SETTABUP
2. NEWTABLE
3. GETUPVAL
4. MOVE

Signed-off-by: Qingping Hou <qingping.hou@gmail.com>
Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
change printk to kp_error

The error info should be printed by kp_error, not printk.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
add memory and events statistics into ktapvm

Support memory allocated/free and events hits/missed stats,
statistics is stored in percpu data.

The statistics data will report after execute script finished.

Usage:

	#./ktap -v scripts/tracepoints/eventcount.kp
	...
	[verbose] ktap stats:
	[verbose] memory allocated size: 473157
	[verbose] memory allocate num: 11039
	[verbose] memory free num: 11039
	[verbose] events_hits: 376981
	[verbose] events_missed: 0

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
kill unused kp_newuserdata function and ktap_udata strucutre

There have no user for kp_newuserdata and ktap_udata, so kill it.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
create synth_tbl in kp_aggrtable_new

This will avoid create synth_tbl multiple times when
using histogram or pairs of aggregation table.

Further more, we only allow create table in mainthread.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
cleanup some comments associated with lua

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
rename ktap_aggrtable to ktap_ptable

Use a more simple name to represent parallel table.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
Introduce <<< operator for new aggregation support

This patch introduce new aggregate operator: <<<
For example:
	s = ptable()
	s["test"] <<< 1
	s["test"] <<< 2
	print(s["test"])    ---> [count: 2 sum: 3 max: 2 min: 1 avg: 1]
	print(count(s["test"])		---> 2
	print(sum(s["test"])		---> 3
	print(max(s["test"])		---> 2
	print(min(s["test"])		---> 1
	print(avg(s["test"])		---> 1

This new aggregation mechanism is borrowed from systemtap,
also old ktap aggregation is killed now.

The reason for this change is new aggregation syntax will be more
easily for end user, "<<<" just look like stream operator, similar
with aggregation in some level.

In implementation, count/sum/max/min value stores in structure
ktap_stat_data, this structure is bind with table tightly, it allocate
with table nodes and array, and resize at same time. This will
avoid much ktap_stat_data memory allocation.

old builtin function "aggr_table" is replaced by "ptable",
which respesent parallel table.

The testcase(test/ptable.kp) and sample scripts are also updated.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
disable preemption when update ktap_stats

Kernel reported below warning in preempt kernel.

    BUG: using smp_processor_id() in preemptible [00000000] code: ktap/1865
    caller is kp_malloc+0xbd/0xd6 [ktapvm]
    CPU: 11 PID: 1865 Comm: ktap Tainted: G           O 3.12.0-rc6+ #5

The reason is we didn't disable preemption when update
percpu variable ktap_stats, this patch fix it.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
rename email name

Use "Jovi Zhangwei" instead of "zhangwei(Jovi)"

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
remove COPYRIGHT file in top-level directory

copyright notice already moved to each file header.

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