From cb1f76532cf3f37ca48dd54b9b2e1cb0f77bba85 Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Wed, 30 Jan 2008 21:24:10 +0000 Subject: [PATCH] Implement GET_STACK_USAGE() macro to get the current kernel thread stack usage. This implemntation made for growing down stack organization like i386/amd64 platforms have, but prefers different machine dependent version if it is present. --- sys/sys/proc.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 13a5d1be06e..98973397edc 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -784,6 +784,20 @@ MALLOC_DECLARE(M_ZOMBIE); curthread->td_pflags &= ~TDP_NOSLEEPING; \ } while (0) +/* + * Get the current kernel thread stack usage. + * Prefer machine dependent version if present. + */ +#ifndef GET_STACK_USAGE +#define GET_STACK_USAGE(total, used) do { \ + struct thread *td = curthread; \ + (total) = td->td_kstack_pages * PAGE_SIZE; \ + (used) = (char *)td->td_kstack + \ + td->td_kstack_pages * PAGE_SIZE - \ + (char *)&td; \ +} while (0) +#endif /* GET_STACK_USAGE */ + #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash]) extern LIST_HEAD(pidhashhead, proc) *pidhashtbl; extern u_long pidhash;