view driver/process_list.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
line wrap: on
line source

/**
 * process_list.c
 * SPE プロセスマネージャ spe_manager
 * プロセスリストとそれを扱うインライン関数など
 */

#include <linux/module.h>     // カーネルモジュール全般

#include "../include/spe_process.h"
#include "process_list.h"
#include "lspe.h"


// プロセスの各状態ごとの番兵ノード
//static spe_process_context_list_t sentry_opened;
//static spe_process_context_list_t sentry_written;
static spe_process_context_list_t sentry_waiting;
//static spe_process_context_list_t sentry_not_released;

// 各論理 SPE が実行しているプロセスのコンテキスト
static spe_process_context_list_t *running_process[SPE_COUNT_MAX];

// プロセスの各状態ごとのプロセス数
// (running はその都度 running_process を確かめるので不要)
static int count_opened       = 0;
static int count_written      = 0;
static int count_waiting      = 0;
static int count_not_released = 0;
static int count_released     = 0;



//=========================================================================================== initialize_process_lists()
/**
 * initialize_process_lists
 * プロセスリストの初期化
 *
 * @return void
 */
void initialize_process_lists(void)
{
	int i, lspe_count = get_lspe_count();


	// 番兵初期化 (自分自身を指しておく)
//	sentry_opened.prev_process       = sentry_opened.next_process       = &sentry_opened;
//	sentry_written.prev_process      = sentry_written.next_process      = &sentry_written;
	sentry_waiting.prev_process      = sentry_waiting.next_process      = &sentry_waiting;
//	sentry_not_released.prev_process = sentry_not_released.next_process = &sentry_not_released;

	// 各論理 SPE の実行プロセスポインタを初期化
	for (i = 0; i < lspe_count; i++)
		clear_running_process(i);
}


//=================================================================================================== increment_opened()
/**
 * increment_opened
 * OPENED 状態のプロセス数を 1 加算する
 *
 * @return void
 */
void increment_opened(void)
{
	count_opened++;
}


//=================================================================================================== decrement_opened()
/**
 * decrement_opened
 * OPENED 状態のプロセス数を 1 減算する
 *
 * @return void
 */
void decrement_opened(void)
{
	count_opened--;
}



//================================================================================================== increment_written()
/**
 * increment_written
 * WRITTEN 状態のプロセス数を 1 加算する
 *
 * @return void
 */
void increment_written(void)
{
	count_written++;
}


//================================================================================================== decrement_written()
/**
 * decrement_written
 * WRITTEN 状態のプロセス数を 1 減算する
 *
 * @return void
 */
void decrement_written(void)
{
	count_written--;
}



//============================================================================================= add_process_to_waiting()
/**
 * add_process_to_waiting
 * WAITING 状態のプロセスリストに SPE プロセスを加える
 *
 * Note: これと同時に count_waiting が 1 加算される。
 *
 * @return void
 */
void add_process_to_waiting(spe_process_context_list_t *this_process)
{
	// リスト更新
	this_process->prev_process                = sentry_waiting.prev_process;
	this_process->next_process                = &sentry_waiting;
	sentry_waiting.prev_process->next_process = this_process;
	sentry_waiting.prev_process               = this_process;
	// プロセス数加算
	count_waiting++;
}


//=========================================================================================== get_next_waiting_process()
/**
 * get_next_waiting_process
 * WAITING 状態のプロセスリストの先頭にあるプロセスを取得する
 *
 * Note: WAITING 状態のプロセスがない場合は NULL になる。
 *
 * Note: WAITING 状態のプロセスを返すだけで、他の処理は何も行わない。
 *       適宜 remove_process_from_waiting 関数などを実行すること。
 *
 * @return spe_process_context_list_t *
 */
spe_process_context_list_t *get_next_waiting_process(void)
{
	spe_process_context_list_t *next_process = sentry_waiting.next_process;

	return (next_process == &sentry_waiting) ? NULL : next_process;
}


//======================================================================================== remove_process_from_waiting()
/**
 * remove_process_from_waiting
 * WAITING 状態のプロセスリストから SPE プロセスを取り除く
 *
 * Note: これと同時に count_waiting が 1 減算される。
 *
 * @return void
 */
void remove_process_from_waiting(spe_process_context_list_t *this_process)
{
	// リスト更新
	this_process->prev_process->next_process = this_process->next_process;
	this_process->next_process->prev_process = this_process->prev_process;
	// プロセス数減算
	count_waiting--;
}



//================================================================================================ get_running_process()
/**
 * get_running_process
 * 論理 SPE が現在実行しているプロセスのコンテキストを取得する
 *
 * @param  int  n                        SPE 番号 (0..x)
 * @return spe_process_context_list_t *  実行中プロセスコンテキストへのポインタ (実行していない場合は NULL)
 */
spe_process_context_list_t *get_running_process(const int n)
{
	return running_process[n];
}


//================================================================================================ set_running_process()
/**
 * set_running_process
 * 論理 SPE が現在実行しているプロセスのコンテキストを設定する
 *
 * @param  int  n                               SPE 番号 (0..x)
 * @param  spe_process_context_list_t *process  プロセスコンテキストへのポインタ
 * @return void
 */
void set_running_process(const int n, const spe_process_context_list_t *const process)
{
	running_process[n] = process;
}


//============================================================================================== clear_running_process()
/**
 * clear_running_process
 * 論理 SPE が現在実行しているプロセスを初期化する
 *
 * @param  int  n  SPE 番号 (0..x)
 * @return void
 */
void clear_running_process(const int n)
{
	running_process[n] = NULL;
}






//============================================================================================= increment_not_released()
/**
 * increment_not_released
 * NOT_RELEASED 状態のプロセス数を 1 加算する
 *
 * @return void
 */
void increment_not_released(void)
{
	count_not_released++;
}


//============================================================================================= decrement_not_released()
/**
 * decrement_not_released
 * NOT_RELEASED 状態のプロセス数を 1 減算する
 *
 * @return void
 */
void decrement_not_released(void)
{
	count_not_released--;
}



//================================================================================================= increment_released()
/**
 * increment_released
 * RELEASED 状態のプロセス数を 1 加算する
 *
 * @return void
 */
void increment_released(void)
{
	count_released++;
}


















//=========================================================================================== get_process_count_opened()
/**
 * get_process_count_opened
 * OPENED 状態のプロセス数を取得する
 *
 * @return int
 */
int get_process_count_opened(void)
{
	return count_opened;
}


//========================================================================================== get_process_count_written()
/**
 * get_process_count_written
 * WRITTEN 状態のプロセス数を取得する
 *
 * @return int
 */
int get_process_count_written(void)
{
	return count_written;
}


//========================================================================================== get_process_count_waiting()
/**
 * get_process_count_waiting
 * WAITING 状態のプロセス数を取得する
 *
 * @return int
 */
int get_process_count_waiting(void)
{
	return count_waiting;
}


//========================================================================================== get_process_count_running()
/**
 * get_process_count_running
 * RUNNING 状態のプロセス数を取得する
 *
 * @return int
 */
int get_process_count_running(void)
{
	int i, lspe_count = get_lspe_count(), ret = 0;
	for (i = 0; i < lspe_count; i++)
	{
		if (running_process[i] != NULL) ret++;
	}
	return ret;
}


//===================================================================================== get_process_count_not_released()
/**
 * get_process_count_not_released
 * NOT_RELEASED 状態のプロセス数を取得する
 *
 * @return int
 */
int get_process_count_not_released(void)
{
	return count_not_released;
}


//========================================================================================= get_process_count_released()
/**
 * get_process_count_released
 * RELEASED 状態のプロセス数を取得する
 *
 * @return int
 */
int get_process_count_released(void)
{
	return count_released;
}