3 #include <minix/sysutil.h>
7 #define SEF_SELF_NAME_MAXLEN 20
8 PRIVATE
char sef_self_name
[SEF_SELF_NAME_MAXLEN
];
9 PRIVATE endpoint_t sef_self_endpoint
;
12 #define SEF_DEBUG_HEADER_MAXLEN 32
13 PRIVATE
time_t sef_debug_boottime
= 0;
14 PRIVATE u32_t sef_debug_system_hz
= 0;
15 PRIVATE
time_t sef_debug_time_sec
= 0;
16 PRIVATE
time_t sef_debug_time_us
= 0;
17 PRIVATE
char sef_debug_header_buff
[SEF_DEBUG_HEADER_MAXLEN
];
18 FORWARD
_PROTOTYPE( void sef_debug_refresh_params
, (void) );
19 PUBLIC
_PROTOTYPE( char* sef_debug_header
, (void) );
21 /* SEF Init prototypes. */
22 EXTERN
_PROTOTYPE( int do_sef_rs_init
, (void) );
23 EXTERN
_PROTOTYPE( int do_sef_init_request
, (message
*m_ptr
) );
25 /* SEF Live update prototypes. */
26 EXTERN
_PROTOTYPE( void do_sef_lu_before_receive
, (void) );
27 EXTERN
_PROTOTYPE( int do_sef_lu_request
, (message
*m_ptr
) );
29 /* SEF Ping prototypes. */
30 EXTERN
_PROTOTYPE( int do_sef_ping_request
, (message
*m_ptr
) );
32 /*===========================================================================*
34 *===========================================================================*/
35 PUBLIC
void sef_startup()
37 /* SEF startup interface for system processes. */
40 /* Get information about self. */
41 r
= sys_whoami(&sef_self_endpoint
, sef_self_name
, SEF_SELF_NAME_MAXLEN
);
43 sef_self_endpoint
= SELF
;
44 sprintf(sef_self_name
, "%s", "Unknown");
47 #if INTERCEPT_SEF_INIT_REQUESTS
48 /* Intercept SEF Init requests. */
49 if(sef_self_endpoint
== RS_PROC_NR
) {
50 if((r
= do_sef_rs_init()) != OK
) {
51 panic("unable to complete init: %d", r
);
57 if((r
= receive(RS_PROC_NR
, &m
)) != OK
) {
58 panic("unable to receive from RS: %d", r
);
60 if(IS_SEF_INIT_REQUEST(&m
)) {
61 if((r
= do_sef_init_request(&m
)) != OK
) {
62 panic("unable to process init request: %d", r
);
66 panic("unable to receive init request");
72 /*===========================================================================*
74 *===========================================================================*/
75 PUBLIC
int sef_receive(endpoint_t src
, message
*m_ptr
)
77 /* SEF receive() interface for system processes. */
82 #if INTERCEPT_SEF_LU_REQUESTS
83 /* Handle SEF Live update before receive events. */
84 do_sef_lu_before_receive();
87 /* Receive and return in case of error. */
88 r
= receive(src
, m_ptr
);
93 #if INTERCEPT_SEF_PING_REQUESTS
94 /* Intercept SEF Ping requests. */
95 if(IS_SEF_PING_REQUEST(m_ptr
)) {
96 if(do_sef_ping_request(m_ptr
) == OK
) {
102 #if INTERCEPT_SEF_LU_REQUESTS
103 /* Intercept SEF Live update requests. */
104 if(IS_SEF_LU_REQUEST(m_ptr
)) {
105 if(do_sef_lu_request(m_ptr
) == OK
) {
111 /* If we get this far, this is not a valid SEF request, return and
112 * let the caller deal with that.
120 /*===========================================================================*
121 * sef_debug_refresh_params *
122 *===========================================================================*/
123 PRIVATE
void sef_debug_refresh_params(void)
125 /* Refresh SEF debug params. */
130 /* Get boottime the first time. */
131 if(!sef_debug_boottime
) {
132 r
= sys_times(NONE
, NULL
, NULL
, NULL
, &sef_debug_boottime
);
134 sef_debug_boottime
= -1;
138 /* Get system hz the first time. */
139 if(!sef_debug_system_hz
) {
140 r
= sys_getinfo(GET_HZ
, &sef_debug_system_hz
,
141 sizeof(sef_debug_system_hz
), 0, 0);
143 sef_debug_system_hz
= -1;
149 if(sef_debug_boottime
!=-1 && sef_debug_system_hz
!=-1) {
150 r
= sys_times(NONE
, NULL
, NULL
, &uptime
, NULL
);
156 /* Compute current time. */
157 if(sef_debug_boottime
==-1 || sef_debug_system_hz
==-1 || uptime
==-1) {
158 sef_debug_time_sec
= 0;
159 sef_debug_time_us
= 0;
162 sef_debug_time_sec
= (time_t) (sef_debug_boottime
163 + (uptime
/sef_debug_system_hz
));
164 sef_debug_time_us
= (uptime
%sef_debug_system_hz
)
165 * 1000000/sef_debug_system_hz
;
169 /*===========================================================================*
171 *===========================================================================*/
172 PUBLIC
char* sef_debug_header(void)
174 /* Build and return a SEF debug header. */
175 sef_debug_refresh_params();
176 sprintf(sef_debug_header_buff
, "%s: time = %ds %06dus",
177 sef_self_name
, sef_debug_time_sec
, sef_debug_time_us
);
179 return sef_debug_header_buff
;