aboutsummaryrefslogblamecommitdiffstats
path: root/include/litmus/gpu_affinity.h
blob: f610f58b1f3bfe66bebe0e35595f74754f8d693e (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                                                               
                                       










                                                                         
                                       



                                                      




                                                                       



                                                                                     














                                                                   



                                                                                
 
                          


                                                                            


                                                                           
      




                                          
#ifndef LITMUS_GPU_AFFINITY_H
#define LITMUS_GPU_AFFINITY_H

#include <litmus/rt_param.h>
#include <litmus/sched_plugin.h>
#include <litmus/litmus.h>

void update_gpu_estimate(struct task_struct* t, lt_t observed);
gpu_migration_dist_t gpu_migration_distance(int a, int b);

static inline void reset_gpu_tracker(struct task_struct* t)
{
	t->rt_param.accum_gpu_time = 0;
	t->rt_param.gpu_time_stamp = 0;
}

static inline void start_gpu_tracker(struct task_struct* t)
{
	t->rt_param.gpu_time_stamp = litmus_clock();
}

static inline void stop_gpu_tracker(struct task_struct* t)
{
	lt_t now = litmus_clock();
	t->rt_param.accum_gpu_time += (now - t->rt_param.gpu_time_stamp);
	t->rt_param.gpu_time_stamp = 0;
}

static inline lt_t get_gpu_time(struct task_struct* t)
{
	lt_t accum = t->rt_param.accum_gpu_time;
	if (t->rt_param.gpu_time_stamp != 0) {
		accum += (litmus_clock() - t->rt_param.gpu_time_stamp);
	}
	return accum;
}

static inline lt_t get_gpu_estimate(struct task_struct* t, gpu_migration_dist_t dist)
{
	int i;
	lt_t val;

	if(dist == MIG_NONE) {
		dist = MIG_LOCAL;
	}

	val = t->rt_param.gpu_migration_est[dist].avg;
	for(i = dist-1; i >= 0; --i) {
		if(t->rt_param.gpu_migration_est[i].avg > val) {
			val = t->rt_param.gpu_migration_est[i].avg;
		}
	}

#if 0
//	int i;
//	fpbuf_t temp = _fp_to_integer(t->rt_param.gpu_migration_est[dist].est);
//	lt_t val = (temp >= 0) ? temp : 0;  // never allow negative estimates...
	lt_t val = t->rt_param.gpu_migration_est[dist].avg;

//	WARN_ON(temp < 0);

	// lower-bound a distant migration to be at least equal to the level
	// below it.
//	for(i = dist-1; (val == 0) && (i >= MIG_LOCAL); --i) {
//		val = _fp_to_integer(t->rt_param.gpu_migration_est[i].est);
//	}
#endif

	return ((val > 0) ? val : dist+1);
}

#endif