Skip to content

Commit

Permalink
libsgxstep: Implement get_core_id() to query logical CPU.
Browse files Browse the repository at this point in the history
  • Loading branch information
jovanbulck committed Nov 14, 2022
1 parent f36e29a commit 0acf7b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions libsgxstep/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ int get_cpu( void )
return sched_getcpu();
}

int get_core_id(int cpu_id)
{
FILE *fd;
ASSERT((fd = fopen("/proc/cpuinfo", "r")) >= 0);

int cur_cpu_id = -1, core_id = -1, core_id_prev = -1;
char buf[100];
while (fgets(buf, sizeof(buf), fd))
{
sscanf(buf, "core id : %d %*[^\n]", &core_id);
if (core_id != core_id_prev)
{
cur_cpu_id++;
if (cur_cpu_id == cpu_id) break;
}
core_id_prev = core_id;
}

debug("Found cpu_id=%d -> core_id=%d", cpu_id, core_id);
ASSERT( cur_cpu_id == cpu_id );
return core_id;
}

unsigned int pstate_max_perf_pct( void )
{
#if HAS_PSTATE
Expand Down
2 changes: 2 additions & 0 deletions libsgxstep/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ int prepare_system_for_benchmark(int pstate_perf_pct);
int restore_system_state(void);
int print_system_settings(void);

int get_core_id(int cpu_id);

#endif

0 comments on commit 0acf7b0

Please sign in to comment.