profile: rewrite syscall tracker for generic profiling code

This commit is contained in:
Balazs Gerofi
2017-02-25 10:58:48 +09:00
parent 989af7e045
commit e2f424846c
7 changed files with 401 additions and 288 deletions

View File

@@ -23,6 +23,7 @@
#include <affinity.h>
#include <syscall.h>
#include <bitops.h>
#include <profile.h>
#define VR_NONE 0x0
#define VR_STACK 0x1
@@ -243,27 +244,6 @@ struct process_vm;
struct vm_regions;
struct vm_range;
//#define TRACK_SYSCALLS
#ifdef TRACK_SYSCALLS
#define TRACK_SYSCALLS_MAX 300
#define __NR_track_syscalls 701
#define TRACK_SYSCALLS_CLEAR 0x01
#define TRACK_SYSCALLS_ON 0x02
#define TRACK_SYSCALLS_OFF 0x04
#define TRACK_SYSCALLS_PRINT 0x08
#define TRACK_SYSCALLS_PRINT_PROC 0x10
void track_syscalls_print_thread_stats(struct thread *thread);
void track_syscalls_print_proc_stats(struct process *proc);
void track_syscalls_accumulate_counters(struct thread *thread,
struct process *proc);
void track_syscalls_alloc_counters(struct thread *thread);
void track_syscalls_dealloc_thread_counters(struct thread *thread);
void track_syscalls_dealloc_proc_counters(struct process *proc);
#endif // TRACK_SYSCALLS
#define HASH_SIZE 73
@@ -565,13 +545,10 @@ struct process {
#define PP_COUNT 2
#define PP_STOP 3
struct mc_perf_event *monitoring_event;
#ifdef TRACK_SYSCALLS
mcs_lock_node_t st_lock;
uint64_t *syscall_times;
uint32_t *syscall_cnts;
uint64_t *offload_times;
uint32_t *offload_cnts;
#endif // TRACK_SYSCALLS
#ifdef PROFILE_ENABLE
mcs_lock_node_t profile_lock;
struct profile_event *profile_events;
#endif // PROFILE_ENABLE
};
void hold_thread(struct thread *ftn);
@@ -644,13 +621,10 @@ struct thread {
fp_regs_struct *fp_regs;
int in_syscall_offload;
#ifdef TRACK_SYSCALLS
int track_syscalls;
uint64_t *syscall_times;
uint32_t *syscall_cnts;
uint64_t *offload_times;
uint32_t *offload_cnts;
#endif // TRACK_SYSCALLS
#ifdef PROFILE_ENABLE
int profile;
struct profile_event *profile_events;
#endif // PROFILE_ENABLE
// signal
struct sig_common *sigcommon;

54
kernel/include/profile.h Normal file
View File

@@ -0,0 +1,54 @@
#ifndef __PROCESS_PROFILE_H_
#define __PROCESS_PROFILE_H_
/* Uncomment this to enable profiling */
#define PROFILE_ENABLE
#ifdef PROFILE_ENABLE
#define PROFILE_SYSCALL_MAX 300
#define PROFILE_OFFLOAD_MAX (PROFILE_SYSCALL_MAX << 1)
#define PROFILE_EVENT_MIN PROFILE_OFFLOAD_MAX
#define __NR_profile 701
#define PROF_PROC 0x80000000
#define PROF_CLEAR 0x01
#define PROF_ON 0x02
#define PROF_OFF 0x04
#define PROF_PRINT 0x08
struct profile_event {
uint32_t cnt;
uint64_t tsc;
};
/*
* The layout of profile events is as follows:
* [0,PROFILE_SYSCALL_MAX) - syscalls
* [PROFILE_SYSCALL_MAX,PROFILE_OFFLOAD_MAX) - syscall offloads
* [PROFILE_OFFLOAD_MAX,PROFILE_EVENT_MAX) - general events
*
* XXX: Make sure to fill in prof_event_names in profile.c
* for each added profiled event.
*/
enum profile_event_type {
PROFILE_page_fault = PROFILE_EVENT_MIN,
PROFILE_mpol_alloc_missed,
PROFILE_EVENT_MAX /* Should be the last event type */
};
struct thread;
struct process;
enum profile_event_type profile_syscall2offload(enum profile_event_type sc);
void profile_event_add(enum profile_event_type type, uint64_t tsc);
void profile_print_thread_stats(struct thread *thread);
void profile_print_proc_stats(struct process *proc);
void profile_accumulate_events(struct thread *thread, struct process *proc);
int profile_alloc_events(struct thread *thread);
void profile_dealloc_thread_events(struct thread *thread);
void profile_dealloc_proc_events(struct process *proc);
#endif // PROFILE_ENABLE
#endif // __PROCESS_PROFILE_H_