Debian Codegraph @

runtime/dyninst/probe_lock.h

raw
1 /* dyninst probe locking header file
2 * Copyright (C) 2012, 2017 Red Hat Inc.
3 *
4 * This file is part of systemtap, and is free software. You can
5 * redistribute it and/or modify it under the terms of the GNU General
6 * Public License (GPL); either version 2, or (at your option) any
7 * later version.
8 */
9
10 #ifndef _STAPDYN_PROBE_LOCK_H
11 #define _STAPDYN_PROBE_LOCK_H
12
13 #include <pthread.h>
14
15 struct stp_probe_lock {
16 #ifdef STP_TIMING
17 atomic_t *skipped;
18 atomic_t *contention;
19 #endif
20 pthread_rwlock_t *lock;
21 unsigned write_p;
22 };
23
24
25 static void
26 stp_unlock_probe(const struct stp_probe_lock *locks, unsigned num_locks)
27 {
28 unsigned i;
29 for (i = num_locks; i-- > 0;) {
30 pthread_rwlock_unlock(locks[i].lock);
31 }
32 }
33
34
35 static unsigned
36 stp_lock_probe(const struct stp_probe_lock *locks, unsigned num_locks)
37 {
38 #if 0 // XXX: should we bother with trylocks in pure userspace?
39 unsigned i, retries = 0;
40 for (i = 0; i < num_locks; ++i) {
41 if (locks[i].write_p)
42 while (!pthread_rwlock_trywrlock(locks[i].lock)) {
43 #if !define(STAP_SUPRESS_TIME_LIMITS_ENABLE)
44 if (++retries > MAXTRYLOCK)
45 goto skip;
46 #endif
47 #ifdef STP_TIMING
48 atomic_inc(locks[i].contention);
49 #endif
50 udelay (TRYLOCKDELAY);
51 }
52 else
53 while (!pthread_rwlock_tryrdlock(locks[i].lock)) {
54 #if !define(STAP_SUPPRESS_TIME_LIMITS_ENABLE)
55 if (++retries > MAXTRYLOCK)
56 goto skip;
57 #endif
58 #ifdef STP_TIMING
59 atomic_inc(locks[i].contention);
60 #endif
61 udelay (TRYLOCKDELAY);
62 }
63 }
64 return 1;
65
66 skip:
67 atomic_inc(skipped_count());
68 #ifdef STP_TIMING
69 atomic_inc(locks[i].skipped);
70 #endif
71 stp_unlock_probe(locks, i);
72 return 0;
73 #else
74 unsigned i;
75 for (i = 0; i < num_locks; ++i) {
76 if (locks[i].write_p)
77 pthread_rwlock_wrlock(locks[i].lock);
78 else
79 pthread_rwlock_rdlock(locks[i].lock);
80 }
81 return 1;
82 #endif
83 }
84
85
86 #endif /* _STAPDYN_PROBE_LOCK_H */
87