File: bulk_module.c

package info (click to toggle)
rtlinux 3.1pre3-3
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 4,896 kB
  • ctags: 4,228
  • sloc: ansic: 26,204; sh: 2,069; makefile: 1,414; perl: 855; tcl: 489; asm: 380; cpp: 42
file content (94 lines) | stat: -rw-r--r-- 1,693 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <linux/errno.h>
#include <linux/kernel.h>
#include <rtl.h>
#include <time.h>

#include <rtl_sched.h>
#include <rtl_debug.h>
#include <rtl_fifo.h>
#include "bulk.h"

pthread_t sender;
int buffer[BUF_SIZE];
int infifo, outfifo;


void *thread_code(void *t)
{
	int n =0;
	int i = 0;

/* 	rtl_printf ("task starts on CPU %d\n", rtl_getcpuid()); */
	for(i=0; i< BUF_SIZE; i++)buffer[i]=i;

	while (n < COUNT*(BUF_SIZE*sizeof(int))) {
		i=rtf_put(outfifo, buffer,(BUF_SIZE*sizeof(int)));
		if(i <= 0){
			pthread_suspend_np(pthread_self());
			i=0;
		}
		else n += i;
	}


	n=0;
	while (n < COUNT*(BUF_SIZE*sizeof(int))) {
		i= rtf_get(infifo, buffer,BUF_SIZE*sizeof(int));
		if(i <= 0){
		       	pthread_suspend_np(pthread_self());
			i=0;
		}
		else n+= i;
	}
	pthread_suspend_np(pthread_self());

	return 0;
}


int my_handler(unsigned int fifo)
{
		pthread_wakeup_np (sender);
		return 0;
}




/* #define DEBUG  */
int init_module(void)
{
	pthread_attr_t attr;
	struct sched_param sched_param;
	int ret;
	int c_in,c_out;

	rtf_destroy(1);
	rtf_destroy(2);
 	c_in = rtf_create(1, 20*1024);
	infifo = 2;
 	c_out = rtf_create(2, 20*1024);
	outfifo = 1;
	if(c_in || c_out){
		printk("RTF bulk test fails to open fifos %d %d\n",c_in,c_out);
		return -1;
	}
	printk("Done with initializing fifos\n");

	pthread_attr_init (&attr);
	sched_param.sched_priority = 4;
	pthread_attr_setschedparam (&attr, &sched_param);
	ret = pthread_create (&sender,  &attr, thread_code, (void *)1);
	rtf_create_handler(1, &my_handler); 
	rtf_create_handler(2, &my_handler); 
	return 0;
}


void cleanup_module(void)
{
	rtf_destroy(1);
	rtf_destroy(2);
	pthread_cancel (sender);
	pthread_join (sender, NULL);
}