source: trunk/kernel/kern/alarm.h @ 674

Last change on this file since 674 was 669, checked in by alain, 4 years ago

1) Introduce up to 4 command lines arguments in the KSH "load" command.
These arguments are transfered to the user process through the
argc/argv mechanism, using the user space "args" vseg.

2) Introduce the named and anonymous "pipes", for inter-process communication
through the pipe() and mkfifo() syscalls.

3) Introduce the "chat" application to validate the two above mechanisms.

4) Improve printk() and assert() fonctions in printk.c.

File size: 5.3 KB
Line 
1/*
2 * alarm.h - timer based kernel alarm specification           
3 *
4 * Author     Alain Greiner (2016,2017,2018,2019,2020)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24
25#ifndef _ALARM_H_
26#define _ALARM_H_
27
28#include <hal_kernel_types.h>
29#include <list.h>
30
31/****  Forward declarations  ****/
32
33struct  thread_s;
34
35/******************************************************************************************
36 *   This structure defines a generic, timer based, kernel alarm.
37 *
38 * - An alarm being attached to a given thread, the alarm descriptor is embedded in the
39 *   thread descriptor. A client thread can use the alarm_start() function to dynamically
40 *   activate the alarm. It can use the alarm_stop() function to desactivate this alarm.
41 * - This kernel alarm is generic, as the alarm handler (executed when the alarm rings),
42 *   and the handler arguments are defined by two pointers <func_ptr> and <args_xp>.
43 * - When an alarm is created by a client thread, it is registered in the list of alarms
44 *   rooted in the core running the client thread. When it is stopped, the alarm is simply
45 *   removed from this list.
46 * - When creating an alarm, the client thread must define an absolute date (in cycles),
47 *   the func_ptr local pointer, and the args_xp extended pointer.
48 * - The list of alarms is ordered by increasing dates. At each TICK received by a core,
49 *   the date of the first registered alarm is compared to the current date (in the
50 *   core_clock() function). The alarm handler is executed when current_date >= alarm_date.
51 * - It is the handler responsability to stop a ringing alarm, or update the date. 
52 *
53 * This mechanism is used bi the almos_mkh implementation of the TCP protocoL.
54 ******************************************************************************************/
55
56typedef struct alarm_s
57{
58    cycle_t        date;           /*! absolute date for handler execution                */
59    void         * func_ptr;       /*! local pointer on alarm handler function            */
60    xptr_t         args_xp;        /*! local pointer on handler arguments                 */
61    list_entry_t   list;           /*! all alarms attached to the same core               */
62}
63alarm_t;
64
65/*******************************************************************************************
66 * This defines the generic prototype for an alarm handler.
67 ******************************************************************************************/
68
69typedef void (alarm_handler_t) ( xptr_t args_xp );
70
71/*******************************************************************************************
72 * This function initializes the alarm descriptor embedded in the thread identified by the
73 * <thread> argument from the <date>, <func_ptr>, <args_ptr> arguments, and registers it
74 * in the ordered list rooted in the core running this <thread>.
75 *******************************************************************************************
76 * @ date       : absolute date (in cycles).
77 * @ func_ptr   : local pointer on the handler to execute when the alarm rings.
78 * @ args_xp    : extended pointer on the handler arguments.
79 * @ thread     : local pointer on the client thread.
80 ******************************************************************************************/
81void alarm_start( cycle_t           date,
82                  void            * func_ptr,
83                  xptr_t            args_xp,
84                  struct thread_s * thread );
85
86/*******************************************************************************************
87 * This function updates the date of the alarm attached to the thread identified by the
88 * <thread> argument. The list of alarms rooted in the core running the client thread
89 * is modified to respect the absolute dates ordering.
90 *******************************************************************************************
91 * @ thread     : local pointer on the client thread.
92 * @ new_date   : absolute new date (in cycles).
93 ******************************************************************************************/
94void alarm_update( struct thread_s * thread,
95                   cycle_t           new_date );
96
97/*******************************************************************************************
98 * This function unlink an alarm identified by the <thread> argument from the list of
99 * alarms rooted in the core descriptor.
100 *******************************************************************************************
101 * @ thread     : local pointer on the client thread.
102 ******************************************************************************************/
103void alarm_stop( struct thread_s * thread );
104
105
106#endif  /* _ALARM_H_ */
Note: See TracBrowser for help on using the repository browser.