Mercurial > hg > Game > Atoc
comparison driver/procfs/processes.c @ 0:42f240cc4bc6
From: 太田 篤志 <atoc@namikilab.tuat.ac.jp>
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 08 Sep 2009 13:44:18 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:42f240cc4bc6 |
---|---|
1 /** | |
2 * processes.c | |
3 * SPE プロセスマネージャ spe_manager | |
4 * procfs エントリ "processes" のハンドラ | |
5 */ | |
6 | |
7 #include <linux/module.h> // カーネルモジュール全般 | |
8 #include <linux/kernel.h> // printk | |
9 #include <linux/semaphore.h> // down_interruptible, up | |
10 #include <linux/spinlock.h> // spin_lock, spin_unlock | |
11 | |
12 #include "../main.h" | |
13 #include "../critical.h" | |
14 #include "../process_list.h" | |
15 #include "processes.h" | |
16 | |
17 | |
18 | |
19 //============================================================================================== procfs_processes_read() | |
20 /** | |
21 * procfs_processes_read | |
22 * procfs エントリ "processes" の read イベントハンドラ | |
23 * | |
24 * @param char * page | |
25 * @param char ** start | |
26 * @param off_t off | |
27 * @param int count | |
28 * @param int * eof | |
29 * @param void * data | |
30 * @return int | |
31 */ | |
32 int procfs_processes_read(char *page, char **start, off_t off, int count, int *eof, void *data) | |
33 { | |
34 int opened, written, waiting, running, not_released, released; | |
35 struct semaphore *semaphore_for_process_list = get_semaphore_for_process_list(); | |
36 spinlock_t *spinlock_for_process_list = get_spinlock_for_process_list(); | |
37 | |
38 | |
39 // Critical Section (semaphore) >>> | |
40 if (down_interruptible(semaphore_for_process_list)) | |
41 goto procfs_processes_read__error1; | |
42 | |
43 // 各 SPE プロセス状態のプロセス数を取得 (セマフォをロックするだけで取得可能なもの) | |
44 opened = get_process_count_opened(); | |
45 written = get_process_count_written(); | |
46 released = get_process_count_released(); | |
47 | |
48 // Critical Section (spinlock) >>> | |
49 spin_lock(spinlock_for_process_list); | |
50 { | |
51 // 各 SPE プロセス状態のプロセス数を取得 (スピンロックも行わないと取得できないもの) | |
52 waiting = get_process_count_waiting(); | |
53 running = get_process_count_running(); | |
54 not_released = get_process_count_not_released(); | |
55 } | |
56 spin_unlock(spinlock_for_process_list); | |
57 // <<< Critical Section (spinlock) | |
58 | |
59 up(semaphore_for_process_list); | |
60 // <<< Critical Section (semaphore) | |
61 | |
62 | |
63 // プロセス数情報を出力する | |
64 *eof = 1; | |
65 return sprintf ( | |
66 page, | |
67 " Processes \n" | |
68 "-------------------------\n" | |
69 " Opened %9d\n" | |
70 " Written %9d\n" | |
71 " Waiting %9d\n" | |
72 " Running %9d\n" | |
73 " Not Released %9d\n" | |
74 " Released %9d\n" | |
75 "-------------------------\n" | |
76 " Total %9d\n", | |
77 opened, written, waiting, running, not_released, released, | |
78 opened + written + waiting + running + not_released + released // Total | |
79 ); | |
80 | |
81 | |
82 procfs_processes_read__error1: | |
83 return -ERESTARTSYS; | |
84 } |