implement /proc/stat
only for sysconf(_SC_NPROCESSORS_ONLN). This enables Intel OpenMP runtime to arrange threads with regard for CPU topology. refs #291
This commit is contained in:
@ -29,6 +29,7 @@
|
|||||||
#include <process.h>
|
#include <process.h>
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <cls.h>
|
#include <cls.h>
|
||||||
|
#include <syscall.h>
|
||||||
|
|
||||||
//#define IOCTL_FUNC_EXTENSION
|
//#define IOCTL_FUNC_EXTENSION
|
||||||
#ifdef IOCTL_FUNC_EXTENSION
|
#ifdef IOCTL_FUNC_EXTENSION
|
||||||
@ -237,6 +238,7 @@ static void post_init(void)
|
|||||||
ihk_mc_spinlock_init(&syscall_lock);
|
ihk_mc_spinlock_init(&syscall_lock);
|
||||||
}
|
}
|
||||||
ap_start();
|
ap_start();
|
||||||
|
create_os_procfs_files();
|
||||||
}
|
}
|
||||||
#ifdef DCFA_RUN
|
#ifdef DCFA_RUN
|
||||||
extern void user_main();
|
extern void user_main();
|
||||||
|
|||||||
@ -151,6 +151,42 @@ static void delete_proc_procfs_file(int pid, char *fname)
|
|||||||
dprintf("delete procfs file: %s done\n", fname);
|
dprintf("delete procfs file: %s done\n", fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief create a procfs file for this operating system
|
||||||
|
* \param fname relative path name from "host:/proc".
|
||||||
|
* \param mode permissions of the file to be created
|
||||||
|
*
|
||||||
|
* Though operate_proc_procfs_file() is intended to create a process
|
||||||
|
* specific file, it is reused to create a OS specific file by
|
||||||
|
* specifying -1 as the pid parameter.
|
||||||
|
*/
|
||||||
|
static void create_os_procfs_file(char *fname, int mode)
|
||||||
|
{
|
||||||
|
const pid_t pid = -1;
|
||||||
|
const int msg = SCD_MSG_PROCFS_CREATE;
|
||||||
|
const int cpuid = ihk_mc_get_processor_id(); /* i.e. BSP */
|
||||||
|
|
||||||
|
operate_proc_procfs_file(pid, fname, msg, mode, cpuid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief create all procfs files for this operating system
|
||||||
|
*/
|
||||||
|
void create_os_procfs_files(void)
|
||||||
|
{
|
||||||
|
char *fname = NULL;
|
||||||
|
size_t n;
|
||||||
|
|
||||||
|
fname = kmalloc(PROCFS_NAME_MAX, IHK_MC_AP_CRITICAL);
|
||||||
|
|
||||||
|
n = snprintf(fname, PROCFS_NAME_MAX, "mcos%d/stat", osnum);
|
||||||
|
if (n >= PROCFS_NAME_MAX) panic("/proc/stat");
|
||||||
|
create_os_procfs_file(fname, 0444);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Create/delete a procfs file for process.
|
* \brief Create/delete a procfs file for process.
|
||||||
*
|
*
|
||||||
@ -297,7 +333,36 @@ void process_procfs_request(unsigned long rarg)
|
|||||||
}
|
}
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else if (!strcmp(p, "stat")) { /* "/proc/stat" */
|
||||||
|
extern int num_processors; /* kernel/ap.c */
|
||||||
|
char *p;
|
||||||
|
size_t remain;
|
||||||
|
int cpu;
|
||||||
|
|
||||||
|
if (offset > 0) {
|
||||||
|
ans = 0;
|
||||||
|
eof = 1;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
p = buf;
|
||||||
|
remain = count;
|
||||||
|
for (cpu = 0; cpu < num_processors; ++cpu) {
|
||||||
|
size_t n;
|
||||||
|
|
||||||
|
n = snprintf(p, remain, "cpu%d\n", cpu);
|
||||||
|
if (n >= remain) {
|
||||||
|
ans = -ENOSPC;
|
||||||
|
eof = 1;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
p += n;
|
||||||
|
}
|
||||||
|
ans = p - buf;
|
||||||
|
eof = 1;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
else {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
dprintf("matched PID: %d.\n", pid);
|
dprintf("matched PID: %d.\n", pid);
|
||||||
|
|||||||
Reference in New Issue
Block a user