aboutsummaryrefslogblamecommitdiffstats
path: root/litmus/server.c
blob: 8afffd25dab7ed869b3f68f0221d635c63c41cd1 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15














                                                                         
                                                          
                                                                         
                                                                                  












                                                             
                                                                   



                          

                           







                                                                        

                                               
                                             
                                     
                       

                                                                      
                       



                                               



                                          
                                                       




                                             
                                        


                                                   











                                                              
                                                                                        
                                                                                          
                                                                    

                                                 
      
                                     


                                     

#include <linux/percpu.h>
#include <linux/sched.h>
#include <linux/list.h>
#include <linux/slab.h>

#include <litmus/litmus.h>
#include <litmus/sched_plugin.h>
#include <litmus/sched_trace.h>
#include <litmus/rt_domain.h>
#include <litmus/trace.h>
#include <litmus/bheap.h>

#define server_job(s) ((s)->job ? *(s)->job : 0)
#define trace_switch(s, type) sched_trace_server_switch_ ##type (	\
        (s)->parent, 0, (s)->sid, server_job(s), (s)->cpu)
#define trace_transition(s, type)					\
	sched_trace_server_switch_ ##type(0, 0, (s)->sid, server_job(s), (s)->cpu)

#define NCS(x) case x: return #x

static const char* server_state_name(enum server_state state)
{
	switch(state) {
		NCS(SS_ACTIVE);
		NCS(SS_REMOVED);
		NCS(SS_BLOCKED);
	default: return "UNKNOWN";
	}
}

void server_init(struct server *server, int sid, int *job, int cpu)
{
	server->sid = sid;
	server->job = job;

	server->cpu = cpu;
	server->parent = 0;
	server->state = SS_REMOVED;
	server->linked = 0;
	server->in_transit = 0;
}

void server_state_change(struct server *server, enum server_state state,
			 unsigned int transit)
{
	enum server_state last = server->state;

	if (!server->in_transit && transit &&
	    server->state == state) {
		return;
	}
	if (server->in_transit == transit && state == server->state) {
		return;
	}

	if (server->in_transit) {
		trace_transition(server, away);
		last = server->last;
	}

	if (server->state == SS_BLOCKED) {
		sched_trace_server_resume(server->sid);
	}

	if (transit) {
		trace_transition(server, to);
	} else {
		if (last == SS_ACTIVE) {
			trace_switch(server, away);
		}

		switch (state) {
		case SS_BLOCKED:
			sched_trace_server_block(server->sid);
			break;
		case SS_ACTIVE:
			trace_switch(server, to);
			break;
		}
	}

 set_state:
#ifdef CONFIG_PREEMPT_STATE_TRACE
        STRACE("server: %d (parent: %d, cpu: %d, job: %d) - (%s:%d)->(%s:%d) at %llu\n",
	       server->sid, server->parent, server->cpu, (server->job) ? *server->job : 0,
	       server_state_name(server->state), server->in_transit,
	       server_state_name(state), transit,
	       litmus_clock());
#endif
	server->last = server->state;
	server->state = state;
	server->in_transit = transit;
}