summaryrefslogtreecommitdiff
path: root/lib/thread.h
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2013-11-18 23:04:27 +0100
committerDonald Sharp <sharpd@cumulusnetworks.com>2016-05-29 20:08:52 -0400
commit9c7753e41a590c9186adb3c836d6ff6f56e6715f (patch)
tree6684654f9f30b03ff588960f50908e8898aedfde /lib/thread.h
parent63b75cdd34d01838049af3cd61b0bd760f44cafe (diff)
lib: unstupidify thread debug information
the library's thread scheduling functions keep track of the thread function's name, so far so good. However, copying the compiler-provided constant into a buffer inside the thread structure is plain useless. Also, strip_funcname() was trying to support something that never happens. Instead, let's use some bytes here to track where threads are scheduled from. Another commit will print that information on crashes. Ripping out useless stuff: -64 bytes in the thread structure Re-add as const ptr: +8 bytes Extra debug info: +12 bytes Signed-off-by: David Lamparter <equinox@opensourcerouting.org> (cherry picked from commit 3493b7731b750cbc62f00be94b624a08ccccf0b2)
Diffstat (limited to 'lib/thread.h')
-rw-r--r--lib/thread.h39
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/thread.h b/lib/thread.h
index 853ef3fb78..66dd9cf788 100644
--- a/lib/thread.h
+++ b/lib/thread.h
@@ -89,9 +89,6 @@ struct thread_master
typedef unsigned char thread_type;
-/* ISO C99 maximum function name length is 63 */
-#define FUNCNAME_LEN 64
-
/* Thread itself. */
struct thread
{
@@ -111,7 +108,9 @@ struct thread
struct timeval real;
struct cpu_thread_history *hist; /* cache pointer to cpu_history */
unsigned long yield; /* yield time in us */
- char funcname[FUNCNAME_LEN];
+ const char *funcname;
+ const char *schedfrom;
+ int schedfrom_line;
};
struct cpu_thread_history
@@ -126,7 +125,7 @@ struct cpu_thread_history
struct time_stats cpu;
#endif
thread_type types;
- char funcname[FUNCNAME_LEN];
+ const char *funcname;
};
/* Clocks supported by Quagga */
@@ -194,15 +193,17 @@ enum quagga_clkid {
#define THREAD_WRITE_OFF(thread) THREAD_OFF(thread)
#define THREAD_TIMER_OFF(thread) THREAD_OFF(thread)
-#define thread_add_read(m,f,a,v) funcname_thread_add_read_write(THREAD_READ,m,f,a,v,#f)
-#define thread_add_write(m,f,a,v) funcname_thread_add_read_write(THREAD_WRITE,m,f,a,v,#f)
-#define thread_add_timer(m,f,a,v) funcname_thread_add_timer(m,f,a,v,#f)
-#define thread_add_timer_msec(m,f,a,v) funcname_thread_add_timer_msec(m,f,a,v,#f)
-#define thread_add_event(m,f,a,v) funcname_thread_add_event(m,f,a,v,#f)
-#define thread_execute(m,f,a,v) funcname_thread_execute(m,f,a,v,#f)
+#define debugargdef const char *funcname, const char *schedfrom, int fromln
+
+#define thread_add_read(m,f,a,v) funcname_thread_add_read_write(THREAD_READ,m,f,a,v,#f,__FILE__,__LINE__)
+#define thread_add_write(m,f,a,v) funcname_thread_add_read_write(THREAD_WRITE,m,f,a,v,#f,__FILE__,__LINE__)
+#define thread_add_timer(m,f,a,v) funcname_thread_add_timer(m,f,a,v,#f,__FILE__,__LINE__)
+#define thread_add_timer_msec(m,f,a,v) funcname_thread_add_timer_msec(m,f,a,v,#f,__FILE__,__LINE__)
+#define thread_add_event(m,f,a,v) funcname_thread_add_event(m,f,a,v,#f,__FILE__,__LINE__)
+#define thread_execute(m,f,a,v) funcname_thread_execute(m,f,a,v,#f,__FILE__,__LINE__)
/* The 4th arg to thread_add_background is the # of milliseconds to delay. */
-#define thread_add_background(m,f,a,v) funcname_thread_add_background(m,f,a,v,#f)
+#define thread_add_background(m,f,a,v) funcname_thread_add_background(m,f,a,v,#f,__FILE__,__LINE__)
/* Prototypes. */
extern struct thread_master *thread_master_create (void);
@@ -211,24 +212,26 @@ extern void thread_master_free_unused(struct thread_master *);
extern struct thread *funcname_thread_add_read_write (int dir, struct thread_master *,
int (*)(struct thread *),
- void *, int, const char*);
+ void *, int, debugargdef);
extern struct thread *funcname_thread_add_timer (struct thread_master *,
int (*)(struct thread *),
- void *, long, const char*);
+ void *, long, debugargdef);
extern struct thread *funcname_thread_add_timer_msec (struct thread_master *,
int (*)(struct thread *),
- void *, long, const char*);
+ void *, long, debugargdef);
extern struct thread *funcname_thread_add_event (struct thread_master *,
int (*)(struct thread *),
- void *, int, const char*);
+ void *, int, debugargdef);
extern struct thread *funcname_thread_add_background (struct thread_master *,
int (*func)(struct thread *),
void *arg,
long milliseconds_to_delay,
- const char *funcname);
+ debugargdef);
extern struct thread *funcname_thread_execute (struct thread_master *,
int (*)(struct thread *),
- void *, int, const char *);
+ void *, int, debugargdef);
+#undef debugargdef
+
extern void thread_cancel (struct thread *);
extern unsigned int thread_cancel_event (struct thread_master *, void *);
extern struct thread *thread_fetch (struct thread_master *, struct thread *);