view tests/005_forJSASS_1/005.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

#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <memory.h>
#include <sys/time.h>

#include "../../include/ioctl.h"
#include "../../include/spe_process.h"


#define  PROGRAM_SIZE  40
#define  PROCESSES     10


volatile unsigned char buffer[1024] __attribute__((aligned(128)));


int main(int argc, char *argv[])
{
	int fd_mmap;
	if ((fd_mmap = open("../../spe_programs/001_overhead/spe", O_RDONLY)) == -1)
	{
		printf("Can't open spe program.\n");
		return -1;
	}
	printf("fd_mmap: %d\n", fd_mmap);

/*
	volatile void *mapped;
	if ((mapped = mmap(NULL, 1024, PROT_READ, MAP_SHARED, fd_mmap, 0)) == MAP_FAILED)
	{
		printf("mmap() failed.\n");
		return -1;
	}
	memcpy(buffer, mapped, 1024);
*/
	read(fd_mmap, buffer, PROGRAM_SIZE);

//------------------------------------------------
//	ここから時間を計測する

	struct timeval tv1, tv2, tv3;
	int fd[PROCESSES];

	gettimeofday(&tv1, NULL);
	gettimeofday(&tv2, NULL);

	spe_process_context_write_data_t spe_write = { 0 };
	spe_process_context_read_data_t  spe_read;

	spe_write.pgm_start = (uint64_t)buffer;
	spe_write.pgm_size  = PROGRAM_SIZE;


	for (int i = 0; i < PROCESSES; i++)
	{
		if ((fd[i] = open("/dev/spe_manager", O_RDWR)) == -1)
		{
			printf("Can't open /dev/spe_manager. (i = %d)\n", i);
			return -1;
		}

		lseek(fd[i], 0, SEEK_SET);
		write(fd[i], &spe_write, sizeof(spe_write));
	}

	for (int i = 0; i < PROCESSES; i++)
	{
		ioctl(fd[i], SPE_MANAGER_IOCTL_START_PROCESS);
	}

	for (int i = 0; i < PROCESSES; i++)
	{
		do
		{
			lseek(fd[i], 0, SEEK_SET);
			read(fd[i], &spe_read, sizeof(spe_read));
		}
		while (spe_read.status != SPE_PROCESS_CONTEXT_STATUS_NOT_RELEASED);
		close(fd[i]);
	}

	gettimeofday(&tv3, NULL);

//	時間計測終了
//------------------------------------------------

	printf("%lu.%06lu\n", tv1.tv_sec, tv1.tv_usec);
	printf("%lu.%06lu\n", tv2.tv_sec, tv2.tv_usec);
	printf("%lu.%06lu\n", tv3.tv_sec, tv3.tv_usec);
	fprintf(stderr, "Done.\n");

	close(fd_mmap);

	return 0;
}