Subversion Repositories shark

Rev

Rev 514 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
495 giacomo 1
/*
2
 * Copyright (c) 1996 The University of Utah and
3
 * the Computer Systems Laboratory at the University of Utah (CSL).
4
 * All rights reserved.
5
 *
6
 * Permission to use, copy, modify and distribute this software is hereby
7
 * granted provided that (1) source code retains these copyright, permission,
8
 * and disclaimer notices, and (2) redistributions including binaries
9
 * reproduce the notices in supporting documentation, and (3) all advertising
10
 * materials mentioning features or use of this software display the following
11
 * acknowledgement: ``This product includes software developed by the
12
 * Computer Systems Laboratory at the University of Utah.''
13
 *
14
 * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
15
 * IS" CONDITION.  THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
16
 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17
 *
18
 * CSL requests users of this software to return to csl-dist@cs.utah.edu any
19
 * improvements that they make and grant CSL redistribution rights.
20
 */
21
/*
22
 * Linux timer support.
23
 */
24
 
25
#include <linuxcomp.h>
26
 
27
#include <linux/kernel.h>
28
#include <linux/timer.h>
29
#include <asm/param.h>
30
 
31
//#define TIMER_DEBUG
32
 
33
//#define IANPATCH
34
#ifndef IANPATCH
35
 
36
static inline void jiffies_to_timespec(unsigned long j, struct timespec *value)
37
{
38
        value->tv_nsec = (j % HZ) * (1000000000L / HZ);
39
        value->tv_sec = j / HZ;
40
}
41
 
42
void add_timer(struct timer_list *timer)
43
{
44
        struct timespec timeout;
45
 
46
        jiffies_to_timespec(timer->expires, &timeout);
47
        if (timer->function)
48
                timer->event_timer = shark_event_post(&timeout, (void (*)(void *))timer->function, (void *)timer->data);
49
 
50
#ifdef TIMER_DEBUG
51
        cprintf("Set to %ld:%ld\n",timeout.tv_sec,timeout.tv_nsec);
52
#endif
53
}
54
 
55
 
56
int del_timer(struct timer_list *timer)
57
{
58
        shark_event_delete(timer->event_timer);
59
        return 0;                               /* TODO */
60
}
61
 
62
int mod_timer(struct timer_list *timer, unsigned long expires)
63
{
64
        shark_event_delete(timer->event_timer);
65
        timer->expires = expires;
66
        add_timer(timer);
67
        return 0;                               /* TODO */
68
}
69
 
70
void init_timer(struct timer_list * timer)
71
{
72
        timer->event_timer = -1;
73
        timer->function = NULL;
74
}
75
 
76
int timer_pending(struct timer_list * timer){
77
        return timer->event_timer != -1;
78
}
79
 
80
#else
81
 
82
/* CHECK!!!! */
83
 
84
#include <pthread.h>
85
 
86
/*Needs to have this sort of thing in the initfile
87
 * PTHREAD_register_module(1, 0, 1);
88
 *
89
 *   TIMER_register_module();
90
 *   PI_register_module();
91
 *   PC_register_module();
92
 */
93
 
94
pthread_attr_t task_attr; /* attributtes for the task doing the callback*/
95
 
96
static inline void
97
jiffies_to_timespec(unsigned long j, struct timespec *value)
98
{
99
        value->tv_nsec = (j % HZ) * (1000000000L / HZ);
100
        value->tv_sec = j / HZ;
101
}
102
 
103
int add_timer(struct timer_list *timer)
104
{
105
  int err;
106
  struct sigevent ev;
107
  struct sched_param task_param;
108
  struct itimerspec timeout;
109
 
110
  ev.sigev_notify            = SIGEV_THREAD;
111
  ev.sigev_value.sival_int   = timer->data;
112
  ev.sigev_notify_function   = timer->function;
113
  ev.sigev_notify_attributes = &task_attr;
114
 
115
  pthread_attr_init(&task_attr);
116
  pthread_attr_setdetachstate(&task_attr, PTHREAD_CREATE_DETACHED);
117
  pthread_attr_setschedpolicy(&task_attr, SCHED_RR);
118
  task_param.sched_priority = 10;
119
  pthread_attr_setschedparam(&task_attr, &task_param);
120
 
121
  err =timer_create(CLOCK_REALTIME, &ev, &(timer->sharktimer));
122
  if (err !=0 ) { cprintf("timer: unable to create timer\n"); }
123
 
124
  timeout.it_interval.tv_sec=0;
125
  timeout.it_interval.tv_nsec=0;
126
  jiffies_to_timespec(timer->expires, &(timeout.it_value));
127
 
128
  err = timer_settime(timer->sharktimer, 0, &timeout, NULL);
129
  if (err !=0 ) { cprintf("timer: unable to timer_settime\n"); }
130
 
131
  return err;
132
}
133
 
134
 
135
void del_timer(struct timer_list *timer)
136
{
137
        timer_delete(timer->sharktimer);
138
}
139
 
140
void mod_timer(struct timer_list *timer, unsigned long expires)
141
{
142
        timer_delete(timer->sharktimer);
143
        timer->expires=expires;
144
        add_timer(timer);
145
}
146
 
147
void init_timer(struct timer_list * timer)
148
{
149
}
150
 
151
#endif