Guest User

Untitled

a guest
Oct 14th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.67 KB | None | 0 0
  1.  
  2. #define STAP_MSG_RUNTIME_H_01 "myproc-unprivileged tapset function called without is_myproc checking for pid %d (euid %d)"
  3. #define STAP_MSG_LOC2C_01 "kernel read fault at 0x%p (%s)"
  4. #define STAP_MSG_LOC2C_02 "kernel write fault at 0x%p (%s)"
  5. #define STAP_MSG_LOC2C_03 "divide by zero in DWARF operand (%s)"
  6. #define STAP_VERSION(a, b) ( ((a) << 8) + (b) )
  7. #ifndef STAP_COMPAT_VERSION
  8. #define STAP_COMPAT_VERSION STAP_VERSION(1, 6)
  9. #endif
  10. #define STP_PRIVILEGED 1
  11. #ifndef MAXNESTING
  12. #define MAXNESTING 5
  13. #endif
  14. #include <asm/types.h>
  15. #ifndef MAXSTRINGLEN
  16. #if BITS_PER_LONG == 32
  17. #define MAXSTRINGLEN 256
  18. #else
  19. #define MAXSTRINGLEN 512
  20. #endif
  21. #endif
  22. #ifndef MAXACTION
  23. #define MAXACTION 1000
  24. #endif
  25. #ifndef MAXACTION_INTERRUPTIBLE
  26. #define MAXACTION_INTERRUPTIBLE (MAXACTION * 10)
  27. #endif
  28. #ifndef TRYLOCKDELAY
  29. #define TRYLOCKDELAY 10 /* microseconds */
  30. #endif
  31. #ifndef MAXTRYLOCK
  32. #define MAXTRYLOCK 100 /* 1 millisecond total */
  33. #endif
  34. #ifndef MAXMAPENTRIES
  35. #define MAXMAPENTRIES 2048
  36. #endif
  37. #ifndef MAXERRORS
  38. #define MAXERRORS 0
  39. #endif
  40. #ifndef MAXSKIPPED
  41. #define MAXSKIPPED 100
  42. #endif
  43. #ifndef MINSTACKSPACE
  44. #define MINSTACKSPACE 1024
  45. #endif
  46. #ifndef INTERRUPTIBLE
  47. #define INTERRUPTIBLE 1
  48. #endif
  49. #ifndef STP_OVERLOAD_INTERVAL
  50. #define STP_OVERLOAD_INTERVAL 1000000000LL
  51. #endif
  52. #ifndef STP_OVERLOAD_THRESHOLD
  53. #define STP_OVERLOAD_THRESHOLD 500000000LL
  54. #endif
  55. #if !defined(STP_NO_OVERLOAD) && !defined(STAP_NO_OVERLOAD)
  56. #define STP_OVERLOAD
  57. #endif
  58. #define STP_SKIP_BADVARS 0
  59. #include "runtime.h"
  60. #include "stack.c"
  61. #include "stat.c"
  62. #include <linux/string.h>
  63. #include <linux/timer.h>
  64. #include <linux/sched.h>
  65. #include <linux/delay.h>
  66. #include <linux/profile.h>
  67. #include <linux/random.h>
  68. #include <linux/vermagic.h>
  69. #include <linux/utsname.h>
  70. #include <linux/version.h>
  71. #include "loc2c-runtime.h"
  72. #include "access_process_vm.h"
  73.  
  74. #include <linux/time.h>
  75.  
  76.  
  77.  
  78. typedef char string_t[MAXSTRINGLEN];
  79.  
  80. #define STAP_SESSION_STARTING 0
  81. #define STAP_SESSION_RUNNING 1
  82. #define STAP_SESSION_ERROR 2
  83. #define STAP_SESSION_STOPPING 3
  84. #define STAP_SESSION_STOPPED 4
  85. static atomic_t session_state = ATOMIC_INIT (STAP_SESSION_STARTING);
  86. static atomic_t error_count = ATOMIC_INIT (0);
  87. static atomic_t skipped_count = ATOMIC_INIT (0);
  88. static atomic_t skipped_count_lowstack = ATOMIC_INIT (0);
  89. static atomic_t skipped_count_reentrant = ATOMIC_INIT (0);
  90. static atomic_t skipped_count_uprobe_reg = ATOMIC_INIT (0);
  91. static atomic_t skipped_count_uprobe_unreg = ATOMIC_INIT (0);
  92.  
  93. #define _STP_REGS_USER_FLAG 1
  94.  
  95. struct context {
  96. atomic_t busy;
  97. const char *probe_point;
  98. const char *probe_name;
  99. int actionremaining;
  100. int nesting;
  101. string_t error_buffer;
  102. #ifdef STAP_NEED_CONTEXT_TOKENIZE
  103. string_t tok_str;
  104. char *tok_start;
  105. char *tok_end;
  106. #endif
  107. const char *last_error;
  108. const char *last_stmt;
  109. struct pt_regs *regs;
  110. #if defined __ia64__
  111. unsigned long *unwaddr;
  112. #endif
  113. struct kretprobe_instance *pi;
  114. int pi_longs;
  115. int regflags;
  116. int regparm;
  117. va_list *mark_va_list;
  118. const char * marker_name;
  119. const char * marker_format;
  120. void *data;
  121. #ifdef STP_OVERLOAD
  122. cycles_t cycles_base;
  123. cycles_t cycles_sum;
  124. #endif
  125. struct uretprobe_instance *ri;
  126. #if defined(STP_NEED_UNWIND_DATA)
  127. struct unwind_context uwcontext;
  128. #endif
  129. union {
  130. struct probe_2962_locals {
  131. string_t __tmp0;
  132. string_t __tmp2;
  133. } probe_2962;
  134. struct probe_2963_locals {
  135. string_t __tmp0;
  136. int64_t __tmp1;
  137. string_t __tmp2;
  138. } probe_2963;
  139. } probe_locals;
  140. union {
  141. struct function___indent_timestamp_locals {
  142. int64_t __retvalue;
  143. } function___indent_timestamp;
  144. struct function__generic_indent_locals {
  145. int64_t ts;
  146. int64_t x;
  147. string_t r;
  148. int64_t i;
  149. int64_t idx;
  150. int64_t delta;
  151. union {
  152. struct {
  153. int64_t __tmp0;
  154. };
  155. struct {
  156. int64_t __tmp2;
  157. int64_t __tmp3;
  158. int64_t __tmp4;
  159. int64_t __tmp5;
  160. int64_t __tmp6;
  161. };
  162. struct {
  163. int64_t __tmp8;
  164. int64_t __tmp10;
  165. int64_t __tmp11;
  166. };
  167. struct {
  168. int64_t __tmp12;
  169. int64_t __tmp13;
  170. int64_t __tmp14;
  171. };
  172. struct {
  173. string_t __tmp16;
  174. int64_t __tmp18;
  175. int64_t __tmp19;
  176. int64_t __tmp20;
  177. string_t __tmp21;
  178. int64_t __tmp22;
  179. string_t __tmp23;
  180. };
  181. struct {
  182. int64_t __tmp29;
  183. };
  184. };
  185. string_t __retvalue;
  186. } function__generic_indent;
  187. struct function_execname_locals {
  188. string_t __retvalue;
  189. } function_execname;
  190. struct function_gettimeofday_ns_locals {
  191. int64_t __retvalue;
  192. } function_gettimeofday_ns;
  193. struct function_gettimeofday_us_locals {
  194. int64_t __tmp0;
  195. int64_t __retvalue;
  196. } function_gettimeofday_us;
  197. struct function_probefunc_locals {
  198. string_t __retvalue;
  199. } function_probefunc;
  200. struct function_thread_indent_locals {
  201. int64_t delta;
  202. int64_t __tmp0;
  203. int64_t __tmp1;
  204. string_t __retvalue;
  205. } function_thread_indent;
  206. struct function_tid_locals {
  207. int64_t __retvalue;
  208. } function_tid;
  209. } locals [MAXNESTING+1];
  210. #if MAXNESTING < 0
  211. #error "MAXNESTING must be positive"
  212. #endif
  213. };
  214.  
  215. static struct context *contexts[NR_CPUS] = { NULL };
  216.  
  217. #include "alloc.c"
  218. #define VALUE_TYPE INT64
  219. #define KEY1_TYPE INT64
  220. #include "map-gen.c"
  221. #undef VALUE_TYPE
  222. #undef KEY1_TYPE
  223. #include "map.c"
  224. #ifdef STAP_NEED_GETTIMEOFDAY
  225. #include "time.c"
  226. #endif
  227.  
  228. #include "probe_lock.h"
  229. static struct {
  230. MAP s__indent_counters;
  231. #ifdef CONFIG_PREEMPT_RT
  232. raw_rwlock_t s__indent_counters_lock;
  233. #else
  234. rwlock_t s__indent_counters_lock;
  235. #endif
  236. #ifdef STP_TIMING
  237. atomic_t s__indent_counters_lock_skip_count;
  238. #endif
  239.  
  240. MAP s__indent_timestamps;
  241. #ifdef CONFIG_PREEMPT_RT
  242. raw_rwlock_t s__indent_timestamps_lock;
  243. #else
  244. rwlock_t s__indent_timestamps_lock;
  245. #endif
  246. #ifdef STP_TIMING
  247. atomic_t s__indent_timestamps_lock_skip_count;
  248. #endif
  249.  
  250. } global = {
  251.  
  252. #ifdef STP_TIMING
  253. .s__indent_counters_lock_skip_count = ATOMIC_INIT(0),
  254. #endif
  255. #ifdef STP_TIMING
  256. .s__indent_timestamps_lock_skip_count = ATOMIC_INIT(0),
  257. #endif
  258. };
  259.  
  260. static void function___indent_timestamp (struct context * __restrict__ c);
  261.  
  262. static void function__generic_indent (struct context * __restrict__ c);
  263.  
  264. static void function_execname (struct context * __restrict__ c);
  265.  
  266. static void function_gettimeofday_ns (struct context * __restrict__ c);
  267.  
  268. static void function_gettimeofday_us (struct context * __restrict__ c);
  269.  
  270. static void function_probefunc (struct context * __restrict__ c);
  271.  
  272. static void function_thread_indent (struct context * __restrict__ c);
  273.  
  274. static void function_tid (struct context * __restrict__ c);
  275.  
  276. static void function___indent_timestamp (struct context* __restrict__ c) {
  277. __label__ out;
  278. struct function___indent_timestamp_locals * __restrict__ l = & c->locals[c->nesting+1].function___indent_timestamp;
  279. (void) l;
  280. #define CONTEXT c
  281. #define THIS l
  282. c->last_stmt = "identifier '__indent_timestamp' at /usr/share//systemtap/tapset/indent-default.stp:1:10";
  283. if (unlikely (c->nesting+1 >= MAXNESTING)) {
  284. c->last_error = "MAXNESTING exceeded";
  285. return;
  286. } else {
  287. c->nesting ++;
  288. }
  289. l->__retvalue = 0;
  290. #define return goto out
  291. l->__retvalue =
  292. ({
  293. function_gettimeofday_us (c);
  294. if (unlikely(c->last_error)) goto out;
  295. c->locals[c->nesting+1].function_gettimeofday_us.__retvalue;
  296. });
  297. c->actionremaining -= 1;
  298. if (unlikely (c->actionremaining <= 0)) {
  299. c->last_error = "MAXACTION exceeded";
  300. c->last_stmt = "keyword at /usr/share//systemtap/tapset/indent-default.stp:1:33";
  301. goto out;
  302. }
  303. goto out;
  304. #undef return
  305. out:
  306. if (0) goto out;
  307. c->nesting --;
  308. #undef CONTEXT
  309. #undef THIS
  310. }
  311.  
  312.  
  313. static void function__generic_indent (struct context* __restrict__ c) {
  314. __label__ out;
  315. struct function__generic_indent_locals * __restrict__ l = & c->locals[c->nesting+1].function__generic_indent;
  316. (void) l;
  317. #define CONTEXT c
  318. #define THIS l
  319. c->last_stmt = "identifier '_generic_indent' at /usr/share//systemtap/tapset/indent.stp:3:10";
  320. if (unlikely (c->nesting+1 >= MAXNESTING)) {
  321. c->last_error = "MAXNESTING exceeded";
  322. return;
  323. } else {
  324. c->nesting ++;
  325. }
  326. l->ts = 0;
  327. l->x = 0;
  328. l->r[0] = '\0';
  329. l->i = 0;
  330. l->__retvalue[0] = '\0';
  331. #define return goto out
  332. {
  333. (void)
  334. ({
  335. l->__tmp0 =
  336. ({
  337. function___indent_timestamp (c);
  338. if (unlikely(c->last_error)) goto out;
  339. c->locals[c->nesting+1].function___indent_timestamp.__retvalue;
  340. });
  341. l->ts = l->__tmp0;
  342. l->__tmp0;
  343. });
  344.  
  345. c->actionremaining -= 2;
  346. if (unlikely (c->actionremaining <= 0)) {
  347. c->last_error = "MAXACTION exceeded";
  348. c->last_stmt = "keyword at /usr/share//systemtap/tapset/indent.stp:6:3";
  349. goto out;
  350. }
  351. if ((! (
  352. ({
  353. l->__tmp2 = l->idx;
  354. l->__tmp3 = _stp_map_get_ii (global.s__indent_counters, l->__tmp2);
  355. l->__tmp3;
  356. })))) {
  357. (void)
  358. ({
  359. l->__tmp4 = l->idx;
  360. l->__tmp5 = l->ts;
  361. c->last_stmt = "identifier '_indent_timestamps' at /usr/share//systemtap/tapset/indent.stp:6:32";
  362. l->__tmp6 = l->__tmp5;
  363. { int rc = _stp_map_set_ii (global.s__indent_timestamps, l->__tmp4, l->__tmp6); if (unlikely(rc)) { c->last_error = "Array overflow, check MAXMAPENTRIES"; goto out; }};
  364. l->__tmp5;
  365. });
  366. c->actionremaining -= 1;
  367. if (unlikely (c->actionremaining <= 0)) {
  368. c->last_error = "MAXACTION exceeded";
  369. c->last_stmt = "identifier '_indent_timestamps' at /usr/share//systemtap/tapset/indent.stp:6:32";
  370. goto out;
  371. }
  372. }
  373.  
  374. (void)
  375. ({
  376. l->__tmp8 = ((
  377. ({
  378. l->__tmp10 = l->idx;
  379. l->__tmp11 = _stp_map_get_ii (global.s__indent_counters, l->__tmp10);
  380. l->__tmp11;
  381. })) + ((((((l->delta) > (((int64_t)0LL))))) ? (l->delta) : (((int64_t)0LL)))));
  382. l->x = l->__tmp8;
  383. l->__tmp8;
  384. });
  385.  
  386. (void)
  387. ({
  388. l->__tmp12 = l->idx;
  389. l->__tmp13 = l->delta;
  390. c->last_stmt = "identifier '_indent_counters' at /usr/share//systemtap/tapset/indent.stp:10:3";
  391. l->__tmp14 = _stp_map_get_ii (global.s__indent_counters, l->__tmp12);
  392. l->__tmp14 += l->__tmp13;
  393. { int rc = _stp_map_set_ii (global.s__indent_counters, l->__tmp12, l->__tmp14); if (unlikely(rc)) { c->last_error = "Array overflow, check MAXMAPENTRIES"; goto out; }};
  394. l->__tmp14;
  395. });
  396.  
  397. (void)
  398. ({
  399. strlcpy (l->__tmp16,
  400. ({
  401. l->__tmp18 = ((l->ts) - (
  402. ({
  403. l->__tmp19 = l->idx;
  404. l->__tmp20 = _stp_map_get_ii (global.s__indent_timestamps, l->__tmp19);
  405. l->__tmp20;
  406. })));
  407. strlcpy (l->__tmp21,
  408. ({
  409. function_execname (c);
  410. if (unlikely(c->last_error)) goto out;
  411. c->locals[c->nesting+1].function_execname.__retvalue;
  412. }), MAXSTRINGLEN);
  413. l->__tmp22 =
  414. ({
  415. function_tid (c);
  416. if (unlikely(c->last_error)) goto out;
  417. c->locals[c->nesting+1].function_tid.__retvalue;
  418. });
  419. _stp_snprintf (l->__tmp23, MAXSTRINGLEN, "%6lld %s(%lld):", l->__tmp18, l->__tmp21, l->__tmp22);
  420. l->__tmp23;
  421. }), MAXSTRINGLEN);
  422. strlcpy (l->r, l->__tmp16, MAXSTRINGLEN);
  423. l->__tmp16;
  424. });
  425.  
  426. (void)
  427. ({
  428. l->i = ((int64_t)1LL);
  429. ((int64_t)1LL);
  430. });
  431. c->actionremaining -= 5;
  432. if (unlikely (c->actionremaining <= 0)) {
  433. c->last_error = "MAXACTION exceeded";
  434. c->last_stmt = "keyword at /usr/share//systemtap/tapset/indent.stp:14:3";
  435. goto out;
  436. }
  437. top_0:
  438. if (! ((((l->i) < (l->x))))) goto break_0;
  439. (void)
  440. ({
  441. strlcat (l->r, " ", MAXSTRINGLEN);
  442. l->r;
  443. });
  444. c->actionremaining -= 2;
  445. if (unlikely (c->actionremaining <= 0)) {
  446. c->last_error = "MAXACTION exceeded";
  447. c->last_stmt = "identifier 'r' at /usr/share//systemtap/tapset/indent.stp:14:23";
  448. goto out;
  449. }
  450. continue_0:
  451. (void)
  452. ({
  453. l->__tmp29 = l->i;
  454. l->i += 1;
  455. l->__tmp29;
  456. });
  457. goto top_0;
  458. break_0:
  459. ; /* dummy statement */
  460.  
  461. strlcpy (l->__retvalue, l->r, MAXSTRINGLEN);
  462. c->actionremaining -= 2;
  463. if (unlikely (c->actionremaining <= 0)) {
  464. c->last_error = "MAXACTION exceeded";
  465. c->last_stmt = "keyword at /usr/share//systemtap/tapset/indent.stp:16:3";
  466. goto out;
  467. }
  468. goto out;
  469.  
  470. }
  471. #undef return
  472. out:
  473. if (0) goto out;
  474. c->nesting --;
  475. #undef CONTEXT
  476. #undef THIS
  477. }
  478.  
  479.  
  480. static void function_execname (struct context* __restrict__ c) {
  481. __label__ out;
  482. struct function_execname_locals * __restrict__ l = & c->locals[c->nesting+1].function_execname;
  483. (void) l;
  484. #define CONTEXT c
  485. #define THIS l
  486. c->last_stmt = "identifier 'execname' at /usr/share//systemtap/tapset/context.stp:33:10";
  487. if (unlikely (c->nesting+1 >= MAXNESTING)) {
  488. c->last_error = "MAXNESTING exceeded";
  489. return;
  490. } else {
  491. c->nesting ++;
  492. }
  493. l->__retvalue[0] = '\0';
  494. #define return goto out
  495. {
  496. /* pure */
  497. strlcpy (THIS->__retvalue, current->comm, MAXSTRINGLEN);
  498.  
  499. }
  500. #undef return
  501. out:
  502. if (0) goto out;
  503. c->nesting --;
  504. #undef CONTEXT
  505. #undef THIS
  506. }
  507.  
  508.  
  509. static void function_gettimeofday_ns (struct context* __restrict__ c) {
  510. __label__ out;
  511. struct function_gettimeofday_ns_locals * __restrict__ l = & c->locals[c->nesting+1].function_gettimeofday_ns;
  512. (void) l;
  513. #define CONTEXT c
  514. #define THIS l
  515. c->last_stmt = "identifier 'gettimeofday_ns' at /usr/share//systemtap/tapset/timestamp.stp:24:10";
  516. if (unlikely (c->nesting+1 >= MAXNESTING)) {
  517. c->last_error = "MAXNESTING exceeded";
  518. return;
  519. } else {
  520. c->nesting ++;
  521. }
  522. l->__retvalue = 0;
  523. #define return goto out
  524. {
  525. /* pure */
  526. /* NOTE: we can't use do_gettimeofday because we could be called from a
  527. * context where xtime_lock is already held. See bug #2525. */
  528. THIS->__retvalue = _stp_gettimeofday_ns();
  529.  
  530. }
  531. #undef return
  532. out:
  533. if (0) goto out;
  534. c->nesting --;
  535. #undef CONTEXT
  536. #undef THIS
  537. }
  538.  
  539.  
  540. static void function_gettimeofday_us (struct context* __restrict__ c) {
  541. __label__ out;
  542. struct function_gettimeofday_us_locals * __restrict__ l = & c->locals[c->nesting+1].function_gettimeofday_us;
  543. (void) l;
  544. #define CONTEXT c
  545. #define THIS l
  546. c->last_stmt = "identifier 'gettimeofday_us' at /usr/share//systemtap/tapset/timestamp.stp:31:10";
  547. if (unlikely (c->nesting+1 >= MAXNESTING)) {
  548. c->last_error = "MAXNESTING exceeded";
  549. return;
  550. } else {
  551. c->nesting ++;
  552. }
  553. l->__retvalue = 0;
  554. #define return goto out
  555. l->__retvalue = ({
  556. l->__tmp0 =
  557. ({
  558. function_gettimeofday_ns (c);
  559. if (unlikely(c->last_error)) goto out;
  560. c->locals[c->nesting+1].function_gettimeofday_ns.__retvalue;
  561. });
  562. if (unlikely(!((int64_t)1000LL))) {
  563. c->last_error = "division by 0";
  564. c->last_stmt = "operator '/' at /usr/share//systemtap/tapset/timestamp.stp:32:28";
  565. goto out;
  566. }
  567. _stp_div64 (NULL, l->__tmp0, ((int64_t)1000LL));
  568. });
  569. c->actionremaining -= 1;
  570. if (unlikely (c->actionremaining <= 0)) {
  571. c->last_error = "MAXACTION exceeded";
  572. c->last_stmt = "keyword at /usr/share//systemtap/tapset/timestamp.stp:32:3";
  573. goto out;
  574. }
  575. goto out;
  576. #undef return
  577. out:
  578. if (0) goto out;
  579. c->nesting --;
  580. #undef CONTEXT
  581. #undef THIS
  582. }
  583.  
  584.  
  585. static void function_probefunc (struct context* __restrict__ c) {
  586. __label__ out;
  587. struct function_probefunc_locals * __restrict__ l = & c->locals[c->nesting+1].function_probefunc;
  588. (void) l;
  589. #define CONTEXT c
  590. #define THIS l
  591. c->last_stmt = "identifier 'probefunc' at /usr/share//systemtap/tapset/context.stp:92:10";
  592. if (unlikely (c->nesting+1 >= MAXNESTING)) {
  593. c->last_error = "MAXNESTING exceeded";
  594. return;
  595. } else {
  596. c->nesting ++;
  597. }
  598. l->__retvalue[0] = '\0';
  599. #define return goto out
  600. {
  601. /* pure */
  602. char *ptr, *start;
  603.  
  604. start = strstr(CONTEXT->probe_point, "function(\"");
  605. ptr = start + 10;
  606. if (!start) {
  607. start = strstr(CONTEXT->probe_point, "inline(\"");
  608. ptr = start + 8;
  609. }
  610.  
  611. if (start) {
  612. int len = MAXSTRINGLEN;
  613. char *dst = THIS->__retvalue;
  614. while (*ptr != '@' && --len > 0 && *ptr)
  615. *dst++ = *ptr++;
  616. *dst = 0;
  617.  
  618. } else if (CONTEXT->regs &&
  619. #if defined (__ia64__)
  620. ((unsigned long)REG_IP(CONTEXT->regs) >= (unsigned long)KERNEL_START)) {
  621. #else
  622. ((unsigned long)REG_IP(CONTEXT->regs) >= (unsigned long)PAGE_OFFSET)) {
  623. #endif
  624. _stp_symbol_sprint_basic(THIS->__retvalue, MAXSTRINGLEN,
  625. REG_IP(CONTEXT->regs));
  626. if (THIS->__retvalue[0] == '.') /* powerpc symbol has a dot*/
  627. strlcpy(THIS->__retvalue,THIS->__retvalue + 1,MAXSTRINGLEN);
  628. } else {
  629. THIS->__retvalue[0] = '\0';
  630. }
  631.  
  632. }
  633. #undef return
  634. out:
  635. if (0) goto out;
  636. c->nesting --;
  637. #undef CONTEXT
  638. #undef THIS
  639. }
  640.  
  641.  
  642. static void function_thread_indent (struct context* __restrict__ c) {
  643. __label__ out;
  644. struct function_thread_indent_locals * __restrict__ l = & c->locals[c->nesting+1].function_thread_indent;
  645. (void) l;
  646. #define CONTEXT c
  647. #define THIS l
  648. c->last_stmt = "identifier 'thread_indent' at /usr/share//systemtap/tapset/indent.stp:19:10";
  649. if (unlikely (c->nesting+1 >= MAXNESTING)) {
  650. c->last_error = "MAXNESTING exceeded";
  651. return;
  652. } else {
  653. c->nesting ++;
  654. }
  655. l->__retvalue[0] = '\0';
  656. #define return goto out
  657. strlcpy (l->__retvalue,
  658. ({
  659. l->__tmp0 =
  660. ({
  661. function_tid (c);
  662. if (unlikely(c->last_error)) goto out;
  663. c->locals[c->nesting+1].function_tid.__retvalue;
  664. });
  665. l->__tmp1 = l->delta;
  666. c->locals[c->nesting+1].function__generic_indent.idx = l->__tmp0;
  667. c->locals[c->nesting+1].function__generic_indent.delta = l->__tmp1;
  668. function__generic_indent (c);
  669. if (unlikely(c->last_error)) goto out;
  670. c->locals[c->nesting+1].function__generic_indent.__retvalue;
  671. }), MAXSTRINGLEN);
  672. c->actionremaining -= 1;
  673. if (unlikely (c->actionremaining <= 0)) {
  674. c->last_error = "MAXACTION exceeded";
  675. c->last_stmt = "keyword at /usr/share//systemtap/tapset/indent.stp:21:3";
  676. goto out;
  677. }
  678. goto out;
  679. #undef return
  680. out:
  681. if (0) goto out;
  682. c->nesting --;
  683. #undef CONTEXT
  684. #undef THIS
  685. }
  686.  
  687.  
  688. static void function_tid (struct context* __restrict__ c) {
  689. __label__ out;
  690. struct function_tid_locals * __restrict__ l = & c->locals[c->nesting+1].function_tid;
  691. (void) l;
  692. #define CONTEXT c
  693. #define THIS l
  694. c->last_stmt = "identifier 'tid' at /usr/share//systemtap/tapset/context.stp:41:10";
  695. if (unlikely (c->nesting+1 >= MAXNESTING)) {
  696. c->last_error = "MAXNESTING exceeded";
  697. return;
  698. } else {
  699. c->nesting ++;
  700. }
  701. l->__retvalue = 0;
  702. #define return goto out
  703. {
  704. /* pure */
  705. THIS->__retvalue = current->pid;
  706.  
  707. }
  708. #undef return
  709. out:
  710. if (0) goto out;
  711. c->nesting --;
  712. #undef CONTEXT
  713. #undef THIS
  714. }
  715.  
  716.  
  717. static void probe_2962 (struct context * __restrict__ c) {
  718. __label__ out;
  719. static const struct stp_probe_lock locks[] = {
  720. {
  721. .lock = &global.s__indent_counters_lock,
  722. .write_p = 1,
  723. #ifdef STP_TIMING
  724. .skipped = &global.s__indent_counters_lock_skip_count,
  725. #endif
  726. },
  727. {
  728. .lock = &global.s__indent_timestamps_lock,
  729. .write_p = 1,
  730. #ifdef STP_TIMING
  731. .skipped = &global.s__indent_timestamps_lock_skip_count,
  732. #endif
  733. },
  734. };
  735. struct probe_2962_locals * __restrict__ l = & c->probe_locals.probe_2962;
  736. (void) l;
  737. #ifndef STP_PRIVILEGED
  738. #error Internal Error: Probe kernel.function("lock_sock@net/core/sock.c:1355") generated in --unprivileged mode
  739. #endif
  740. if (!stp_lock_probe(locks, ARRAY_SIZE(locks)))
  741. return;
  742. (void)
  743. ({
  744. strlcpy (l->__tmp0,
  745. ({
  746. c->locals[c->nesting+1].function_thread_indent.delta = ((int64_t)1LL);
  747. function_thread_indent (c);
  748. if (unlikely(c->last_error)) goto out;
  749. c->locals[c->nesting+1].function_thread_indent.__retvalue;
  750. }), MAXSTRINGLEN);
  751. strlcpy (l->__tmp2,
  752. ({
  753. function_probefunc (c);
  754. if (unlikely(c->last_error)) goto out;
  755. c->locals[c->nesting+1].function_probefunc.__retvalue;
  756. }), MAXSTRINGLEN);
  757. _stp_printf ("%s -> %s \n", l->__tmp0, l->__tmp2);
  758. ((int64_t)0LL);
  759. });
  760. c->actionremaining -= 1;
  761. if (unlikely (c->actionremaining <= 0)) {
  762. c->last_error = "MAXACTION exceeded";
  763. c->last_stmt = "identifier 'printf' at /tmp/psock.stp:10:2";
  764. goto out;
  765. }
  766. out:
  767. stp_unlock_probe(locks, ARRAY_SIZE(locks));
  768. _stp_print_flush();
  769. }
  770.  
  771.  
  772. static void probe_2963 (struct context * __restrict__ c) {
  773. __label__ out;
  774. static const struct stp_probe_lock locks[] = {
  775. {
  776. .lock = &global.s__indent_counters_lock,
  777. .write_p = 1,
  778. #ifdef STP_TIMING
  779. .skipped = &global.s__indent_counters_lock_skip_count,
  780. #endif
  781. },
  782. {
  783. .lock = &global.s__indent_timestamps_lock,
  784. .write_p = 1,
  785. #ifdef STP_TIMING
  786. .skipped = &global.s__indent_timestamps_lock_skip_count,
  787. #endif
  788. },
  789. };
  790. struct probe_2963_locals * __restrict__ l = & c->probe_locals.probe_2963;
  791. (void) l;
  792. #ifndef STP_PRIVILEGED
  793. #error Internal Error: Probe kernel.function("release_sock@net/core/sock.c:1367").return generated in --unprivileged mode
  794. #endif
  795. if (!stp_lock_probe(locks, ARRAY_SIZE(locks)))
  796. return;
  797. (void)
  798. ({
  799. strlcpy (l->__tmp0,
  800. ({
  801. l->__tmp1 = ((int64_t)-1LL);
  802. c->locals[c->nesting+1].function_thread_indent.delta = l->__tmp1;
  803. function_thread_indent (c);
  804. if (unlikely(c->last_error)) goto out;
  805. c->locals[c->nesting+1].function_thread_indent.__retvalue;
  806. }), MAXSTRINGLEN);
  807. strlcpy (l->__tmp2,
  808. ({
  809. function_probefunc (c);
  810. if (unlikely(c->last_error)) goto out;
  811. c->locals[c->nesting+1].function_probefunc.__retvalue;
  812. }), MAXSTRINGLEN);
  813. _stp_printf ("%s <- %s\n", l->__tmp0, l->__tmp2);
  814. ((int64_t)0LL);
  815. });
  816. c->actionremaining -= 1;
  817. if (unlikely (c->actionremaining <= 0)) {
  818. c->last_error = "MAXACTION exceeded";
  819. c->last_stmt = "identifier 'printf' at /tmp/psock.stp:15:2";
  820. goto out;
  821. }
  822. out:
  823. stp_unlock_probe(locks, ARRAY_SIZE(locks));
  824. _stp_print_flush();
  825. }
  826.  
  827. static struct stap_probe {
  828. void (* const ph) (struct context*);
  829. #ifdef STP_ALIBI
  830. atomic_t alibi;
  831. #define STAP_PROBE_INIT_ALIBI() .alibi=ATOMIC_INIT(0),
  832. #else
  833. #define STAP_PROBE_INIT_ALIBI()
  834. #endif
  835. #ifdef STP_TIMING
  836. Stat timing;
  837. #endif
  838. #if defined(STP_TIMING) || defined(STP_ALIBI)
  839. const char location[22];
  840. const char derivation[66];
  841. #define STAP_PROBE_INIT_TIMING(L, D) .location=(L), .derivation=(D),
  842. #else
  843. #define STAP_PROBE_INIT_TIMING(L, D)
  844. #endif
  845. const char pp[64];
  846. #ifdef STP_NEED_PROBE_NAME
  847. const char pn[64];
  848. #define STAP_PROBE_INIT_NAME(PN) .pn=(PN),
  849. #else
  850. #define STAP_PROBE_INIT_NAME(PN)
  851. #endif
  852. #define STAP_PROBE_INIT(PH, PP, PN, L, D) { .ph=(PH), .pp=(PP), STAP_PROBE_INIT_NAME(PN) STAP_PROBE_INIT_ALIBI() STAP_PROBE_INIT_TIMING(L, D) }
  853. } stap_probes[] = {
  854. STAP_PROBE_INIT(&probe_2962, "kernel.function(\"lock_sock@net/core/sock.c:1355\")", "kernel.function(\"lock_sock@net/core/sock.c:1355\")", "/tmp/psock.stp:9:1", " from: kernel.function(\"lock_sock@net/core/sock.c\")"),
  855. STAP_PROBE_INIT(&probe_2963, "kernel.function(\"release_sock@net/core/sock.c:1367\").return", "kernel.function(\"release_sock@net/core/sock.c:1367\").return", "/tmp/psock.stp:14:1", " from: kernel.function(\"release_sock@net/core/sock.c\").return"),
  856. };
  857.  
  858. /* ---- dwarf probes ---- */
  859. #if ! defined(CONFIG_KPROBES)
  860. #error "Need CONFIG_KPROBES!"
  861. #endif
  862.  
  863. #ifndef KRETACTIVE
  864. #define KRETACTIVE (max(15,6*(int)num_possible_cpus()))
  865. #endif
  866. #include "kprobes-common.h"
  867. static int enter_kprobe_probe (struct kprobe *inst, struct pt_regs *regs);
  868. static int enter_kretprobe_probe (struct kretprobe_instance *inst, struct pt_regs *regs);
  869. #if defined(STAPCONF_UNREGISTER_KPROBES)
  870. static void * stap_unreg_kprobes[2];
  871. #endif
  872. static struct stap_dwarf_kprobe stap_dwarf_kprobes[2];
  873. static struct stap_dwarf_probe {
  874. const unsigned return_p:1;
  875. const unsigned maxactive_p:1;
  876. const unsigned optional_p:1;
  877. unsigned registered_p:1;
  878. const unsigned short maxactive_val;
  879. const unsigned short saved_longs;
  880. const unsigned short saved_strings;
  881. const char module[7];
  882. const char section[7];
  883. const unsigned long address;
  884. struct stap_probe * const probe;
  885. struct stap_probe * const entry_probe;
  886. } stap_dwarf_probes[] = {
  887. { .address=(unsigned long)0x167b53ULL, .module="kernel", .section="_stext", .probe=(&stap_probes[0]), },
  888. { .return_p=1, .address=(unsigned long)0x167a9cULL, .module="kernel", .section="_stext", .probe=(&stap_probes[1]), },
  889. };
  890.  
  891. static int enter_kprobe_probe (struct kprobe *inst, struct pt_regs *regs) {
  892. int kprobe_idx = ((uintptr_t)inst-(uintptr_t)stap_dwarf_kprobes)/sizeof(struct stap_dwarf_kprobe);
  893. struct stap_dwarf_probe *sdp = &stap_dwarf_probes[((kprobe_idx >= 0 && kprobe_idx < 2)?kprobe_idx:0)];
  894. #ifdef STP_ALIBI
  895. atomic_inc(&(sdp->probe->alibi));
  896. #else
  897. struct context* __restrict__ c;
  898. #if !INTERRUPTIBLE
  899. unsigned long flags;
  900. #endif
  901. #if defined(STP_TIMING) || defined(STP_OVERLOAD)
  902. cycles_t cycles_atstart = get_cycles ();
  903. #endif
  904. #ifdef STP_TIMING
  905. Stat stat = sdp->probe->timing;
  906. #endif
  907. #if INTERRUPTIBLE
  908. preempt_disable ();
  909. #else
  910. local_irq_save (flags);
  911. #endif
  912. if (unlikely ((((unsigned long) (& c)) & (THREAD_SIZE-1))
  913. < (MINSTACKSPACE + sizeof (struct thread_info)))) {
  914. atomic_inc (& skipped_count);
  915. #ifdef STP_TIMING
  916. atomic_inc (& skipped_count_lowstack);
  917. #endif
  918. goto probe_epilogue;
  919. }
  920. if (atomic_read (&session_state) != STAP_SESSION_RUNNING)
  921. goto probe_epilogue;
  922. c = contexts[smp_processor_id()];
  923. if (atomic_inc_return (& c->busy) != 1) {
  924. #if !INTERRUPTIBLE
  925. atomic_inc (& skipped_count);
  926. #endif
  927. #ifdef STP_TIMING
  928. atomic_inc (& skipped_count_reentrant);
  929. #ifdef DEBUG_REENTRANCY
  930. _stp_warn ("Skipped %s due to %s residency on cpu %u\n", sdp->probe->pp, c->probe_point ?: "?", smp_processor_id());
  931. #endif
  932. #endif
  933. atomic_dec (& c->busy);
  934. goto probe_epilogue;
  935. }
  936.  
  937. c->last_stmt = 0;
  938. c->last_error = 0;
  939. c->nesting = -1;
  940. c->regs = 0;
  941. #if defined __ia64__
  942. c->unwaddr = 0;
  943. #endif
  944. c->probe_point = sdp->probe->pp;
  945. #ifdef STP_NEED_PROBE_NAME
  946. c->probe_name = sdp->probe->pn;
  947. #else
  948. c->probe_name = 0;
  949. #endif
  950. c->pi = 0;
  951. c->pi_longs = 0;
  952. c->regflags = 0;
  953. c->regparm = 0;
  954. c->marker_name = NULL;
  955. c->marker_format = NULL;
  956. #if INTERRUPTIBLE
  957. c->actionremaining = MAXACTION_INTERRUPTIBLE;
  958. #else
  959. c->actionremaining = MAXACTION;
  960. #endif
  961. c->ri = 0;
  962. c->regs = regs;
  963. {
  964. unsigned long kprobes_ip = REG_IP(c->regs);
  965. SET_REG_IP(regs, (unsigned long) inst->addr);
  966. (*sdp->probe->ph) (c);
  967. SET_REG_IP(regs, kprobes_ip);
  968. }
  969. #if defined(STP_TIMING) || defined(STP_OVERLOAD)
  970. {
  971. cycles_t cycles_atend = get_cycles ();
  972. int32_t cycles_elapsed = ((int32_t)cycles_atend > (int32_t)cycles_atstart)
  973. ? ((int32_t)cycles_atend - (int32_t)cycles_atstart)
  974. : (~(int32_t)0) - (int32_t)cycles_atstart + (int32_t)cycles_atend + 1;
  975. #ifdef STP_TIMING
  976. if (likely (stat)) _stp_stat_add(stat, cycles_elapsed);
  977. #endif
  978. #ifdef STP_OVERLOAD
  979. {
  980. cycles_t interval = (cycles_atend > c->cycles_base)
  981. ? (cycles_atend - c->cycles_base)
  982. : (STP_OVERLOAD_INTERVAL + 1);
  983. c->cycles_sum += cycles_elapsed;
  984. if (interval > STP_OVERLOAD_INTERVAL) {
  985. if (c->cycles_sum > STP_OVERLOAD_THRESHOLD) {
  986. _stp_error ("probe overhead exceeded threshold");
  987. atomic_set (&session_state, STAP_SESSION_ERROR);
  988. atomic_inc (&error_count);
  989. }
  990. c->cycles_base = cycles_atend;
  991. c->cycles_sum = 0;
  992. }
  993. }
  994. #endif
  995. }
  996. #endif
  997. c->probe_point = 0;
  998. c->probe_name = 0;
  999. if (unlikely (c->last_error && c->last_error[0])) {
  1000. if (c->last_stmt != NULL)
  1001. _stp_softerror ("%s near %s", c->last_error, c->last_stmt);
  1002. else
  1003. _stp_softerror ("%s", c->last_error);
  1004. atomic_inc (& error_count);
  1005. if (atomic_read (& error_count) > MAXERRORS) {
  1006. atomic_set (& session_state, STAP_SESSION_ERROR);
  1007. _stp_exit ();
  1008. }
  1009. }
  1010. atomic_dec (&c->busy);
  1011. probe_epilogue:
  1012. if (unlikely (atomic_read (& skipped_count) > MAXSKIPPED)) {
  1013. if (unlikely (pseudo_atomic_cmpxchg(& session_state, STAP_SESSION_RUNNING, STAP_SESSION_ERROR) == STAP_SESSION_RUNNING))
  1014. _stp_error ("Skipped too many probes, check MAXSKIPPED or try again with stap -t for more details.");
  1015. }
  1016. #if INTERRUPTIBLE
  1017. preempt_enable_no_resched ();
  1018. #else
  1019. local_irq_restore (flags);
  1020. #endif
  1021. #endif // STP_ALIBI
  1022. return 0;
  1023. }
  1024.  
  1025. static int enter_kretprobe_common (struct kretprobe_instance *inst, struct pt_regs *regs, int entry) {
  1026. struct kretprobe *krp = inst->rp;
  1027. int kprobe_idx = ((uintptr_t)krp-(uintptr_t)stap_dwarf_kprobes)/sizeof(struct stap_dwarf_kprobe);
  1028. struct stap_dwarf_probe *sdp = &stap_dwarf_probes[((kprobe_idx >= 0 && kprobe_idx < 2)?kprobe_idx:0)];
  1029. struct stap_probe *sp = entry ? sdp->entry_probe : sdp->probe;
  1030. if (sp) {
  1031. #ifdef STP_ALIBI
  1032. atomic_inc(&(sp->alibi));
  1033. #else
  1034. struct context* __restrict__ c;
  1035. #if !INTERRUPTIBLE
  1036. unsigned long flags;
  1037. #endif
  1038. #if defined(STP_TIMING) || defined(STP_OVERLOAD)
  1039. cycles_t cycles_atstart = get_cycles ();
  1040. #endif
  1041. #ifdef STP_TIMING
  1042. Stat stat = sp->timing;
  1043. #endif
  1044. #if INTERRUPTIBLE
  1045. preempt_disable ();
  1046. #else
  1047. local_irq_save (flags);
  1048. #endif
  1049. if (unlikely ((((unsigned long) (& c)) & (THREAD_SIZE-1))
  1050. < (MINSTACKSPACE + sizeof (struct thread_info)))) {
  1051. atomic_inc (& skipped_count);
  1052. #ifdef STP_TIMING
  1053. atomic_inc (& skipped_count_lowstack);
  1054. #endif
  1055. goto probe_epilogue;
  1056. }
  1057. if (atomic_read (&session_state) != STAP_SESSION_RUNNING)
  1058. goto probe_epilogue;
  1059. c = contexts[smp_processor_id()];
  1060. if (atomic_inc_return (& c->busy) != 1) {
  1061. #if !INTERRUPTIBLE
  1062. atomic_inc (& skipped_count);
  1063. #endif
  1064. #ifdef STP_TIMING
  1065. atomic_inc (& skipped_count_reentrant);
  1066. #ifdef DEBUG_REENTRANCY
  1067. _stp_warn ("Skipped %s due to %s residency on cpu %u\n", sp->pp, c->probe_point ?: "?", smp_processor_id());
  1068. #endif
  1069. #endif
  1070. atomic_dec (& c->busy);
  1071. goto probe_epilogue;
  1072. }
  1073.  
  1074. c->last_stmt = 0;
  1075. c->last_error = 0;
  1076. c->nesting = -1;
  1077. c->regs = 0;
  1078. #if defined __ia64__
  1079. c->unwaddr = 0;
  1080. #endif
  1081. c->probe_point = sp->pp;
  1082. #ifdef STP_NEED_PROBE_NAME
  1083. c->probe_name = sp->pn;
  1084. #else
  1085. c->probe_name = 0;
  1086. #endif
  1087. c->pi = 0;
  1088. c->pi_longs = 0;
  1089. c->regflags = 0;
  1090. c->regparm = 0;
  1091. c->marker_name = NULL;
  1092. c->marker_format = NULL;
  1093. #if INTERRUPTIBLE
  1094. c->actionremaining = MAXACTION_INTERRUPTIBLE;
  1095. #else
  1096. c->actionremaining = MAXACTION;
  1097. #endif
  1098. c->ri = 0;
  1099. c->regs = regs;
  1100. c->pi = inst;
  1101. c->pi_longs = sdp->saved_longs;
  1102. {
  1103. unsigned long kprobes_ip = REG_IP(c->regs);
  1104. if (entry)
  1105. SET_REG_IP(regs, (unsigned long) inst->rp->kp.addr);
  1106. else
  1107. SET_REG_IP(regs, (unsigned long)inst->ret_addr);
  1108. (sp->ph) (c);
  1109. SET_REG_IP(regs, kprobes_ip);
  1110. }
  1111. #if defined(STP_TIMING) || defined(STP_OVERLOAD)
  1112. {
  1113. cycles_t cycles_atend = get_cycles ();
  1114. int32_t cycles_elapsed = ((int32_t)cycles_atend > (int32_t)cycles_atstart)
  1115. ? ((int32_t)cycles_atend - (int32_t)cycles_atstart)
  1116. : (~(int32_t)0) - (int32_t)cycles_atstart + (int32_t)cycles_atend + 1;
  1117. #ifdef STP_TIMING
  1118. if (likely (stat)) _stp_stat_add(stat, cycles_elapsed);
  1119. #endif
  1120. #ifdef STP_OVERLOAD
  1121. {
  1122. cycles_t interval = (cycles_atend > c->cycles_base)
  1123. ? (cycles_atend - c->cycles_base)
  1124. : (STP_OVERLOAD_INTERVAL + 1);
  1125. c->cycles_sum += cycles_elapsed;
  1126. if (interval > STP_OVERLOAD_INTERVAL) {
  1127. if (c->cycles_sum > STP_OVERLOAD_THRESHOLD) {
  1128. _stp_error ("probe overhead exceeded threshold");
  1129. atomic_set (&session_state, STAP_SESSION_ERROR);
  1130. atomic_inc (&error_count);
  1131. }
  1132. c->cycles_base = cycles_atend;
  1133. c->cycles_sum = 0;
  1134. }
  1135. }
  1136. #endif
  1137. }
  1138. #endif
  1139. c->probe_point = 0;
  1140. c->probe_name = 0;
  1141. if (unlikely (c->last_error && c->last_error[0])) {
  1142. if (c->last_stmt != NULL)
  1143. _stp_softerror ("%s near %s", c->last_error, c->last_stmt);
  1144. else
  1145. _stp_softerror ("%s", c->last_error);
  1146. atomic_inc (& error_count);
  1147. if (atomic_read (& error_count) > MAXERRORS) {
  1148. atomic_set (& session_state, STAP_SESSION_ERROR);
  1149. _stp_exit ();
  1150. }
  1151. }
  1152. atomic_dec (&c->busy);
  1153. probe_epilogue:
  1154. if (unlikely (atomic_read (& skipped_count) > MAXSKIPPED)) {
  1155. if (unlikely (pseudo_atomic_cmpxchg(& session_state, STAP_SESSION_RUNNING, STAP_SESSION_ERROR) == STAP_SESSION_RUNNING))
  1156. _stp_error ("Skipped too many probes, check MAXSKIPPED or try again with stap -t for more details.");
  1157. }
  1158. #if INTERRUPTIBLE
  1159. preempt_enable_no_resched ();
  1160. #else
  1161. local_irq_restore (flags);
  1162. #endif
  1163. #endif // STP_ALIBI
  1164. }
  1165. return 0;
  1166. }
  1167.  
  1168. static int enter_kretprobe_probe (struct kretprobe_instance *inst, struct pt_regs *regs) {
  1169. return enter_kretprobe_common(inst, regs, 0);
  1170. }
  1171.  
  1172. static int enter_kretprobe_entry_probe (struct kretprobe_instance *inst, struct pt_regs *regs) {
  1173. return enter_kretprobe_common(inst, regs, 1);
  1174. }
  1175.  
  1176. #include "kprobes-common.c"
  1177.  
  1178.  
  1179. static int systemtap_module_init (void) {
  1180. int rc = 0;
  1181. int cpu;
  1182. int i=0, j=0;
  1183. const char *probe_point = "";
  1184. {
  1185. const char* release = UTS_RELEASE;
  1186. if (strcmp (release, "2.6.16.60-0.81.99.14.6d9b710-default")) {
  1187. _stp_error ("module release mismatch (%s vs %s)", release, "2.6.16.60-0.81.99.14.6d9b710-default");
  1188. rc = -EINVAL;
  1189. }
  1190. if (_stp_module_check()) rc = -EINVAL;
  1191. }
  1192. if (rc) goto out;
  1193. #ifdef STAP_NEED_GETTIMEOFDAY
  1194. rc = _stp_init_time();
  1195. if (rc) {
  1196. _stp_error ("couldn't initialize gettimeofday");
  1197. goto out;
  1198. }
  1199. #endif
  1200. (void) probe_point;
  1201. (void) i;
  1202. (void) j;
  1203. atomic_set (&session_state, STAP_SESSION_STARTING);
  1204. for_each_possible_cpu(cpu) {
  1205. contexts[cpu] = _stp_kzalloc(sizeof(struct context));
  1206. if (contexts[cpu] == NULL) {
  1207. _stp_error ("context (size %lu) allocation failed", (unsigned long) sizeof (struct context));
  1208. rc = -ENOMEM;
  1209. goto out;
  1210. }
  1211. }
  1212. global.s__indent_counters = _stp_map_new_ii (MAXMAPENTRIES); if (global.s__indent_counters == NULL) rc = -ENOMEM;
  1213. if (rc) {
  1214. _stp_error ("global variable '_indent_counters' allocation failed");
  1215. goto out;
  1216. }
  1217. rwlock_init (& global.s__indent_counters_lock);
  1218. global.s__indent_timestamps = _stp_map_new_ii (MAXMAPENTRIES); if (global.s__indent_timestamps == NULL) rc = -ENOMEM;
  1219. if (rc) {
  1220. _stp_error ("global variable '_indent_timestamps' allocation failed");
  1221. goto out;
  1222. }
  1223. rwlock_init (& global.s__indent_timestamps_lock);
  1224. #ifdef STP_TIMING
  1225. for (i = 0; i < ARRAY_SIZE(stap_probes); ++i)
  1226. stap_probes[i].timing = _stp_stat_init (HIST_NONE);
  1227. #endif
  1228. _stp_print_kernel_info("1.6/0.148", (num_online_cpus() * sizeof(struct context)), 2);
  1229. for (i=0; i<2; i++) {
  1230. struct stap_dwarf_probe *sdp = & stap_dwarf_probes[i];
  1231. struct stap_dwarf_kprobe *kp = & stap_dwarf_kprobes[i];
  1232. unsigned long relocated_addr = _stp_kmodule_relocate (sdp->module, sdp->section, sdp->address);
  1233. if (relocated_addr == 0) continue;
  1234. probe_point = sdp->probe->pp;
  1235. if (sdp->return_p) {
  1236. kp->u.krp.kp.addr = (void *) relocated_addr;
  1237. if (sdp->maxactive_p) {
  1238. kp->u.krp.maxactive = sdp->maxactive_val;
  1239. } else {
  1240. kp->u.krp.maxactive = KRETACTIVE;
  1241. }
  1242. kp->u.krp.handler = &enter_kretprobe_probe;
  1243. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
  1244. if (sdp->entry_probe) {
  1245. kp->u.krp.entry_handler = &enter_kretprobe_entry_probe;
  1246. kp->u.krp.data_size = sdp->saved_longs * sizeof(int64_t) +
  1247. sdp->saved_strings * MAXSTRINGLEN;
  1248. }
  1249. #endif
  1250. #ifdef __ia64__
  1251. kp->dummy.addr = kp->u.krp.kp.addr;
  1252. kp->dummy.pre_handler = NULL;
  1253. rc = register_kprobe (& kp->dummy);
  1254. if (rc == 0) {
  1255. rc = register_kretprobe (& kp->u.krp);
  1256. if (rc != 0)
  1257. unregister_kprobe (& kp->dummy);
  1258. }
  1259. #else
  1260. rc = register_kretprobe (& kp->u.krp);
  1261. #endif
  1262. } else {
  1263. kp->u.kp.addr = (void *) relocated_addr;
  1264. kp->u.kp.pre_handler = &enter_kprobe_probe;
  1265. #ifdef __ia64__
  1266. kp->dummy.addr = kp->u.kp.addr;
  1267. kp->dummy.pre_handler = NULL;
  1268. rc = register_kprobe (& kp->dummy);
  1269. if (rc == 0) {
  1270. rc = register_kprobe (& kp->u.kp);
  1271. if (rc != 0)
  1272. unregister_kprobe (& kp->dummy);
  1273. }
  1274. #else
  1275. rc = register_kprobe (& kp->u.kp);
  1276. #endif
  1277. }
  1278. if (rc) {
  1279. sdp->registered_p = 0;
  1280. if (!sdp->optional_p)
  1281. _stp_warn ("probe %s (address 0x%lx) registration error (rc %d)", probe_point, (unsigned long) relocated_addr, rc);
  1282. rc = 0;
  1283. }
  1284. else sdp->registered_p = 1;
  1285. }
  1286. if (rc) {
  1287. _stp_error ("probe %s registration error (rc %d)", probe_point, rc);
  1288. atomic_set (&session_state, STAP_SESSION_ERROR);
  1289. goto out;
  1290. }
  1291. if (atomic_read (&session_state) == STAP_SESSION_STARTING)
  1292. atomic_set (&session_state, STAP_SESSION_RUNNING);
  1293. return 0;
  1294. out:
  1295. _stp_map_del (global.s__indent_counters);
  1296. _stp_map_del (global.s__indent_timestamps);
  1297. atomic_set (&session_state, STAP_SESSION_STOPPED);
  1298. #ifdef STAPCONF_SYNCHRONIZE_SCHED
  1299. synchronize_sched();
  1300. #endif
  1301. #ifdef STAP_NEED_GETTIMEOFDAY
  1302. _stp_kill_time();
  1303. #endif
  1304. for_each_possible_cpu(cpu) {
  1305. if (contexts[cpu] != NULL) {
  1306. _stp_kfree(contexts[cpu]);
  1307. contexts[cpu] = NULL;
  1308. }
  1309. }
  1310. return rc;
  1311. }
  1312.  
  1313.  
  1314. static void systemtap_module_exit (void) {
  1315. int holdon;
  1316. int i=0, j=0;
  1317. int cpu;
  1318. unsigned long hold_start;
  1319. int hold_index;
  1320. (void) i;
  1321. (void) j;
  1322. if (atomic_read (&session_state) == STAP_SESSION_STARTING)
  1323. return;
  1324. if (atomic_read (&session_state) == STAP_SESSION_RUNNING)
  1325. atomic_set (&session_state, STAP_SESSION_STOPPING);
  1326. #if defined(STAPCONF_UNREGISTER_KPROBES)
  1327. j = 0;
  1328. for (i=0; i<2; i++) {
  1329. struct stap_dwarf_probe *sdp = & stap_dwarf_probes[i];
  1330. struct stap_dwarf_kprobe *kp = & stap_dwarf_kprobes[i];
  1331. if (! sdp->registered_p) continue;
  1332. if (!sdp->return_p)
  1333. stap_unreg_kprobes[j++] = &kp->u.kp;
  1334. }
  1335. unregister_kprobes((struct kprobe **)stap_unreg_kprobes, j);
  1336. j = 0;
  1337. for (i=0; i<2; i++) {
  1338. struct stap_dwarf_probe *sdp = & stap_dwarf_probes[i];
  1339. struct stap_dwarf_kprobe *kp = & stap_dwarf_kprobes[i];
  1340. if (! sdp->registered_p) continue;
  1341. if (sdp->return_p)
  1342. stap_unreg_kprobes[j++] = &kp->u.krp;
  1343. }
  1344. unregister_kretprobes((struct kretprobe **)stap_unreg_kprobes, j);
  1345. #ifdef __ia64__
  1346. j = 0;
  1347. for (i=0; i<2; i++) {
  1348. struct stap_dwarf_probe *sdp = & stap_dwarf_probes[i];
  1349. struct stap_dwarf_kprobe *kp = & stap_dwarf_kprobes[i];
  1350. if (! sdp->registered_p) continue;
  1351. stap_unreg_kprobes[j++] = &kp->dummy;
  1352. }
  1353. unregister_kprobes((struct kprobe **)stap_unreg_kprobes, j);
  1354. #endif
  1355. #endif
  1356. for (i=0; i<2; i++) {
  1357. struct stap_dwarf_probe *sdp = & stap_dwarf_probes[i];
  1358. struct stap_dwarf_kprobe *kp = & stap_dwarf_kprobes[i];
  1359. if (! sdp->registered_p) continue;
  1360. if (sdp->return_p) {
  1361. #if !defined(STAPCONF_UNREGISTER_KPROBES)
  1362. unregister_kretprobe (&kp->u.krp);
  1363. #endif
  1364. atomic_add (kp->u.krp.nmissed, & skipped_count);
  1365. #ifdef STP_TIMING
  1366. if (kp->u.krp.nmissed)
  1367. _stp_warn ("Skipped due to missed kretprobe/1 on '%s': %d\n", sdp->probe->pp, kp->u.krp.nmissed);
  1368. #endif
  1369. atomic_add (kp->u.krp.kp.nmissed, & skipped_count);
  1370. #ifdef STP_TIMING
  1371. if (kp->u.krp.kp.nmissed)
  1372. _stp_warn ("Skipped due to missed kretprobe/2 on '%s': %lu\n", sdp->probe->pp, kp->u.krp.kp.nmissed);
  1373. #endif
  1374. } else {
  1375. #if !defined(STAPCONF_UNREGISTER_KPROBES)
  1376. unregister_kprobe (&kp->u.kp);
  1377. #endif
  1378. atomic_add (kp->u.kp.nmissed, & skipped_count);
  1379. #ifdef STP_TIMING
  1380. if (kp->u.kp.nmissed)
  1381. _stp_warn ("Skipped due to missed kprobe on '%s': %lu\n", sdp->probe->pp, kp->u.kp.nmissed);
  1382. #endif
  1383. }
  1384. #if !defined(STAPCONF_UNREGISTER_KPROBES) && defined(__ia64__)
  1385. unregister_kprobe (&kp->dummy);
  1386. #endif
  1387. sdp->registered_p = 0;
  1388. }
  1389. #ifdef STAPCONF_SYNCHRONIZE_SCHED
  1390. synchronize_sched();
  1391. #endif
  1392. hold_start = jiffies;
  1393. hold_index = -1;
  1394. do {
  1395. int i;
  1396. holdon = 0;
  1397. for (i=0; i < NR_CPUS; i++)
  1398. if (cpu_possible (i) && contexts[i] != NULL && atomic_read (& contexts[i]->busy)) {
  1399. holdon = 1;
  1400. if (time_after(jiffies, hold_start + HZ) && (i > hold_index)) {
  1401. hold_index = i;
  1402. printk(KERN_ERR "%s context[%d] stuck: %s\n", THIS_MODULE->name, i, contexts[i]->probe_point);
  1403. }
  1404. }
  1405. #ifdef STAP_OVERRIDE_STUCK_CONTEXT
  1406. if (time_after(jiffies, hold_start + HZ*10)) {
  1407. printk(KERN_ERR "%s overriding stuck context to allow module shutdown.", THIS_MODULE->name);
  1408. holdon = 0;
  1409. }
  1410. #else
  1411. msleep (250);
  1412. #endif
  1413. yield ();
  1414. } while (holdon);
  1415. atomic_set (&session_state, STAP_SESSION_STOPPED);
  1416. #ifdef STAPCONF_SYNCHRONIZE_SCHED
  1417. synchronize_sched();
  1418. #endif
  1419. _stp_map_del (global.s__indent_counters);
  1420. _stp_map_del (global.s__indent_timestamps);
  1421. for_each_possible_cpu(cpu) {
  1422. if (contexts[cpu] != NULL) {
  1423. _stp_kfree(contexts[cpu]);
  1424. contexts[cpu] = NULL;
  1425. }
  1426. }
  1427. #if defined(STP_TIMING) || defined(STP_ALIBI)
  1428. _stp_printf("----- probe hit report: \n");
  1429. for (i = 0; i < ARRAY_SIZE(stap_probes); ++i) {
  1430. struct stap_probe *const p = &stap_probes[i];
  1431. #ifdef STP_ALIBI
  1432. int alibi = atomic_read(&(p->alibi));
  1433. if (alibi)
  1434. _stp_printf ("%s, (%s), hits: %d,%s\n",
  1435. p->pp, p->location, alibi, p->derivation);
  1436. #endif
  1437. #ifdef STP_TIMING
  1438. if (likely (p->timing)) {
  1439. struct stat_data *stats = _stp_stat_get (p->timing, 0);
  1440. if (stats->count) {
  1441. int64_t avg = _stp_div64 (NULL, stats->sum, stats->count);
  1442. _stp_printf ("%s, (%s), hits: %lld, cycles: %lldmin/%lldavg/%lldmax,%s\n",
  1443. p->pp, p->location, (long long) stats->count,
  1444. (long long) stats->min, (long long) avg, (long long) stats->max,
  1445. p->derivation);
  1446. }
  1447. _stp_stat_del (p->timing);
  1448. }
  1449. #endif
  1450. }
  1451. _stp_print_flush();
  1452. #endif
  1453. #ifdef STAP_NEED_GETTIMEOFDAY
  1454. _stp_kill_time();
  1455. #endif
  1456. if (atomic_read (& skipped_count) || atomic_read (& error_count) || atomic_read (& skipped_count_reentrant)) {
  1457. _stp_warn ("Number of errors: %d, skipped probes: %d\n", (int) atomic_read (& error_count), (int) atomic_read (& skipped_count));
  1458. #ifdef STP_TIMING
  1459. {
  1460. int ctr;
  1461. ctr = atomic_read (& global.s__indent_counters_lock_skip_count);
  1462. if (ctr) _stp_warn ("Skipped due to global '%s' lock timeout: %d\n", "_indent_counters", ctr);
  1463. ctr = atomic_read (& global.s__indent_timestamps_lock_skip_count);
  1464. if (ctr) _stp_warn ("Skipped due to global '%s' lock timeout: %d\n", "_indent_timestamps", ctr);
  1465. ctr = atomic_read (& skipped_count_lowstack);
  1466. if (ctr) _stp_warn ("Skipped due to low stack: %d\n", ctr);
  1467. ctr = atomic_read (& skipped_count_reentrant);
  1468. if (ctr) _stp_warn ("Skipped due to reentrancy: %d\n", ctr);
  1469. ctr = atomic_read (& skipped_count_uprobe_reg);
  1470. if (ctr) _stp_warn ("Skipped due to uprobe register failure: %d\n", ctr);
  1471. ctr = atomic_read (& skipped_count_uprobe_unreg);
  1472. if (ctr) _stp_warn ("Skipped due to uprobe unregister failure: %d\n", ctr);
  1473. }
  1474. #endif
  1475. _stp_print_flush();
  1476. }
  1477. }
  1478.  
  1479.  
  1480. static int probe_start (void) {
  1481. return systemtap_module_init () ? -1 : 0;
  1482. }
  1483.  
  1484. static void probe_exit (void) {
  1485. systemtap_module_exit ();
  1486. }
  1487. #include "stap-symbols.h"
  1488. MODULE_DESCRIPTION("systemtap-generated probe");
  1489. MODULE_LICENSE("GPL");
  1490.  
  1491. #undef _indent_counters
  1492.  
  1493. #undef _indent_timestamps
Add Comment
Please, Sign In to add comment