Skip to content

Commit

Permalink
Merged in yu1bai/pmbench (pull request #2)
Browse files Browse the repository at this point in the history
log to ftrace for large access latency

Approved-by: Jisoo <[email protected]>
  • Loading branch information
yu1bai authored and Jisoo committed Jul 7, 2017
2 parents 170b30c + 1a3ace4 commit 96ec2a6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
5 changes: 3 additions & 2 deletions access.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ uint32_t measure_write(uint32_t *ptr)
_code
uint32_t access_histogram(uint32_t *ptr, int is_write)
{
if (is_write) return measure_write(ptr);
return measure_read(ptr);
uint32_t latency;
latency = is_write ? measure_write(ptr) : measure_read(ptr);
return mark_long_latency(latency);
}


Expand Down
8 changes: 8 additions & 0 deletions pmbench.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static struct argp_option options[] = {
{ "ratio", 'r', "RATIO", 0, "Percentage read/write ratio (0 = write only, 100 = read only; default 50)" }, //TODO: count # of reads/writes
{ "offset", 'o', "OFFSET", 0, "Specify static page access offset (default random)" },
{ "initialize", 'i', 0, OPTION_ARG_OPTIONAL, "Initialize memory map with garbage data" },
{ "threshold", 'h', "THRESHOLD", 0, "Set the threshold time to trigger the ftrace log" },
#ifdef PMB_XML
{ "file", 'f', "FILE", 0, "Filename for XML output" },
#endif
Expand Down Expand Up @@ -118,6 +119,7 @@ void set_default_params(parameters* p)
p->tsops = &rdtscp_ops;
p->jobs = 1;
p->init_garbage = 0;
p->threshold = 0;
#ifdef XALLOC
p->xalloc_mib = 0;
p->xalloc_path = "/dev/ram0";
Expand Down Expand Up @@ -152,6 +154,7 @@ void print_params(const parameters* p)
#endif
printf(" offset = "); if (p->offset < 0) printf("random\n"); else printf("%d\n", p->offset);
printf(" ratio = %d%%\n", p->ratio);
printf(" threshold = %d\n", p->threshold);
if (p->pattern && p->pattern->name) {
printf(" pattern = %s\n", p->pattern->name);
}
Expand Down Expand Up @@ -249,6 +252,9 @@ error_t parse_opt(int key, char* arg, struct argp_state* state)
}
param->get_offset = get_offset_function(param->offset);
break;
case 'h':
param->threshold = (arg ? atoi(arg) : 0);
break;
#ifdef PMB_XML
case 'f':
if (arg) {
Expand Down Expand Up @@ -1106,6 +1112,7 @@ int main(int argc, char** argv)
sys_stat_mem_init(&mem_ctx);
control.interrupted = 0;
install_ctrlc_handler();
trace_marker_init();

#ifdef PMB_THREAD
perform_benchmark_mt(buf, stats);
Expand Down Expand Up @@ -1190,6 +1197,7 @@ int main(int argc, char** argv)
#endif

remove_ctrlc_handler();
trace_marker_exit();
return 0;

report_no_unmap:
Expand Down
1 change: 1 addition & 0 deletions pmbench.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ typedef struct parameters {
struct sys_timestamp* tsops;// timestamp ops (rdtsc_ops or perfc_ops)
int jobs; // number of worker threads
int init_garbage;
int threshold;
#ifdef XALLOC
int xalloc_mib; // positive xalloc_mib indicates we use xalloc instead of mmap
char* xalloc_path; // xalloc backend file pathname
Expand Down
34 changes: 34 additions & 0 deletions system.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "rdtsc.h"
#include "cpuid.h"
#include "pattern.h"
#include "pmbench.h"

/*
* for leaf with ecx subleaf, this structure only caches ECX=0 leaf.
Expand Down Expand Up @@ -1307,4 +1308,37 @@ char* sys_get_uuid(void)
{
return uuid_str;
}

static int trace_maker_fd;
void trace_marker_init()
{
trace_maker_fd = open("/sys/kernel/debug/tracing/trace_marker", O_WRONLY);
if (-1 == trace_maker_fd) {
perror("ftrace_init open trace_marker failed");
}
}

_code
uint32_t mark_long_latency(uint32_t nsec)
{
char buf[64];
if (params.threshold == 0) return nsec;

if (trace_maker_fd >= 0 && nsec >= params.threshold) {
sprintf(buf, "latency > %" PRIu32 "ns: %" PRIu32, params.threshold, nsec);
if (-1 == write(trace_maker_fd, buf, strlen(buf))) {
perror("mark_long_latency failed");
}
}
return nsec;
}

void trace_marker_exit()
{
if (trace_maker_fd >= 0) {
if (-1 == close(trace_maker_fd)) {
perror("ftrace_finish close trace_maker_fd failed");
}
}
}
#endif
4 changes: 4 additions & 0 deletions system.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ extern int get_cache_info(int i, int m);
extern char* sys_get_hostname(void);
extern char* sys_get_uuid(void);

extern void trace_marker_init();
extern uint32_t mark_long_latency(uint32_t nsec);
extern void trace_marker_exit();

//XXX ugly..
extern int gl_tlb_info_buf_len;
extern int gl_det_cache_info_len;
Expand Down

0 comments on commit 96ec2a6

Please sign in to comment.