x86, ptrace: new ptrace BTS API
Subsystems (2)
PATCH 4/5 x86, ptrace: new ptrace BTS API
Here's the new ptrace BTS API that supports two different overflow handling mechanisms (wrap-around and buffer-full-signal) to support two different use cases (debugging and profiling).
It further combines buffer allocation and configuration.
Opens:
- memory rlimit
- overflow signal
What would be the right signal to use?
---
arch/x86/kernel/ds.c +51 -5
@@ -177,18 +177,20 @@ } -int ds_allocate (void **dsp,size_t bts_size_in_records) +int ds_allocate (void **dsp,size_t bts_size_in_bytes) { -size_t bts_size_in_bytes =0 ; -void *bts =0 ; -void *ds =0 ; +size_t bts_size_in_records; +void *bts; +void *ds;if (!ds_cfg.sizeof_ds || !ds_cfg.sizeof_bts)return -EOPNOTSUPP ; -if (bts_size_in_records <0 ) +if (bts_size_in_bytes <0 )return -EINVAL ; + bts_size_in_records = + bts_size_in_bytes / ds_cfg.sizeof_bts; bts_size_in_bytes = bts_size_in_records * ds_cfg.sizeof_bts;
@@ -233,9 +235,21 @@if (!ds_cfg.sizeof_ds || !ds_cfg.sizeof_bts)return -EOPNOTSUPP ; +if (!ds) +return 0 ; + size_in_bytes =get_bts_absolute_maximum (ds) -get_bts_buffer_base (ds); +return size_in_bytes; +} + +int ds_get_bts_end (void *ds) +{ +size_t size_in_bytes =ds_get_bts_size (ds); + +if (size_in_bytes <=0 ) +return size_in_bytes;return size_in_bytes / ds_cfg.sizeof_bts; }
@@ -254,6 +268,38 @@return index_offset_in_bytes / ds_cfg.sizeof_bts; } +int ds_set_overflow (void *ds,int method) +{ +switch (method) { +case DS_O_SIGNAL : +return -EOPNOTSUPP ; +case DS_O_WRAP : +return 0 ; +default : +return -EINVAL ; + } +} + +int ds_get_overflow (void *ds) +{ +return DS_O_WRAP ; +} + +int ds_clear (void *ds) +{ +int bts_size =ds_get_bts_size (ds); +void *bts_base; + +if (bts_size <=0 ) +return bts_size; + + bts_base =get_bts_buffer_base (ds); +memset (bts_base,0 , bts_size); + +set_bts_index (ds, bts_base); +return 0 ; +} +int ds_read_bts (void *ds,size_t index,struct bts_struct *out) {void *bts;
arch/x86/kernel/ptrace.c +130 -91
317 lines not on this page · raw message
include/asm-x86/ds.h +7 -0
@@ -52,11 +52,18 @@ } variant; }; +/* Overflow handling mechanisms */ +#define DS_O_SIGNAL 1/* send overflow signal */ +#define DS_O_WRAP 2/* wrap around */ extern int ds_allocate (void **,size_t );extern int ds_free (void **);extern int ds_get_bts_size (void *); +extern int ds_get_bts_end (void *);extern int ds_get_bts_index (void *); +extern int ds_set_overflow (void *,int ); +extern int ds_get_overflow (void *); +extern int ds_clear (void *);extern int ds_read_bts (void *,size_t ,struct bts_struct *);extern int ds_write_bts (void *,const struct bts_struct *);extern unsigned long ds_debugctl_mask (void );
include/asm-x86/ptrace-abi.h +48 -46
99 lines not on this page · raw message
include/asm-x86/ptrace.h +1 -0
@@ -9,6 +9,7 @@#ifdef __KERNEL__ +/* the DS BTS struct is used for ptrace as well */ #include <asm/ds.h> struct task_struct ;
---------------------------------------------------------------------
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen Germany
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Douglas Lusk, Peter Gleissner, Hannes Schwaderer
Registergericht: Muenchen HRB 47456 Ust.-IdNr.
VAT Registration No.: DE129385895
Citibank Frankfurt (BLZ 502 109 00) 600119052
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
Quoted 11 lines · Markus Metzger
Here's the new ptrace BTS API that supports two different overflow handling mechanisms (wrap-around and buffer-full-signal) to support two different use cases (debugging and profiling).
It further combines buffer allocation and configuration.
Opens:
- memory rlimit
- overflow signalWhat would be the right signal to use?
i think we tend to have such signal targets configurable (like in the POSIX timers APIs) - or we could use SIGIO. I've Cc:-ed Ulrich - maybe he has some specific ideas how to structure this.
Ingo