diff --git a/kernel/init.c b/kernel/init.c index 6339c2b0..a8d7fbf8 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -29,6 +29,7 @@ #include #include #include +#include //#define IOCTL_FUNC_EXTENSION #ifdef IOCTL_FUNC_EXTENSION @@ -237,6 +238,7 @@ static void post_init(void) ihk_mc_spinlock_init(&syscall_lock); } ap_start(); + create_os_procfs_files(); } #ifdef DCFA_RUN extern void user_main(); diff --git a/kernel/procfs.c b/kernel/procfs.c index 49a0a5b5..fac2d3bc 100644 --- a/kernel/procfs.c +++ b/kernel/procfs.c @@ -151,6 +151,42 @@ static void delete_proc_procfs_file(int pid, char *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. * @@ -297,7 +333,36 @@ void process_procfs_request(unsigned long rarg) } 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; } dprintf("matched PID: %d.\n", pid);