Beispiel #1
0
static void *
remove_my_node(int arg1, void *arg2) {
	int counter = 10;
	dbg(DBG_TEST, "Invoke remove_mynode\n");

	int rand_number, i=0;	

	while (counter > 0) {
		check_sleep("remove");

		kmutex_lock(&mynode.my_mutex);

		check_sleep("remove");
		
		if (mynode.length > 0) {
			mynode.length--;
			counter--;
		}

		dbg(DBG_TEST, "Remove node: %d\n", mynode.length);		
		kmutex_unlock(&mynode.my_mutex);
	}
	
	return NULL;
}
Beispiel #2
0
void simple_condwait(void)
{
	unsigned long long start;
	mutex_t mutex;
	cond_t cond;
	struct cond_mutex cm = {
		.mutex = &mutex,
		.cond = &cond,
	};
	thread_t cond_signaler_tid;

	fprintf(stderr, "%s\n", __FUNCTION__);

	check("mutex_init", mutex_init(&mutex, PTHREAD_MUTEX_DEFAULT, 0), 0);
	check("cond_init", cond_init(&cond, 0), 0);
	check("mutex_lock", mutex_lock(&mutex), 0);
	check("thread_spawn",
	      thread_spawn(&cond_signaler_tid, 2, cond_signaler, &cm), 0);
	thread_msleep(11);

	start = rt_timer_tsc();
	check("cond_wait", cond_wait(&cond, &mutex, XN_INFINITE), 0);
	check_sleep("cond_wait", start);
	thread_msleep(10);
	check("mutex_unlock", mutex_unlock(&mutex), 0);
	check("thread_join", thread_join(cond_signaler_tid), 0);
	check("mutex_destroy", mutex_destroy(&mutex), 0);
	check("cond_destroy", cond_destroy(&cond), 0);
}
Beispiel #3
0
void cond_destroy_whilewait(void)
{
	unsigned long long start;
	mutex_t mutex;
	cond_t cond;
	struct cond_mutex cm = {
		.mutex = &mutex,
		.cond = &cond,
		.tid = thread_self(),
	};
	thread_t cond_destroyer_tid;
	struct sigaction sa = {
		.sa_handler = sighandler,
		.sa_flags = SA_RESTART,
	};
	sigemptyset(&sa.sa_mask);

	fprintf(stderr, "%s\n", __FUNCTION__);

	check_unix("sigaction", sigaction(SIGRTMIN, &sa, NULL), 0);
	check("mutex_init", mutex_init(&mutex, PTHREAD_MUTEX_DEFAULT, 0), 0);
	check("cond_init", cond_init(&cond, 0), 0);
	check("mutex_lock", mutex_lock(&mutex), 0);
	check("thread_spawn",
	      thread_spawn(&cond_destroyer_tid, 2, cond_destroyer, &cm), 0);
	thread_msleep(11);

	start = rt_timer_tsc();

#ifdef XENO_POSIX
	check("cond_wait", cond_wait(&cond, &mutex, 10 * NS_PER_MS), -ETIMEDOUT);
	check_sleep("cond_wait", start);
	thread_msleep(10);

	check("mutex_unlock", mutex_unlock(&mutex), 0);
#else /* native */
	check("cond_wait", cond_wait(&cond, &mutex, XN_INFINITE), -EIDRM);
	check_sleep("cond_wait", start);
#endif /* native */
	check("thread_join", thread_join(cond_destroyer_tid), 0);
	check("mutex_destroy", mutex_destroy(&mutex), 0);
#ifdef XENO_POSIX
	check("cond_destroy", cond_destroy(&cond), 0);
#else /* native */
	check("cond_destroy", cond_destroy(&cond), -ESRCH);
#endif /* native */
}
Beispiel #4
0
int main(int argc, const char *argv[])
{
	unsigned long long start;
	int dev, dev2;

	printf("Setup\n");
	check("modprobe", system("modprobe xeno_rtdmtest"), 0);
	dev = check_no_error("open", open(devname, O_RDWR));

	printf("Exclusive open\n");
	check("open", open(devname, O_RDWR), -EBUSY);

	printf("Successive open\n");
	dev2 = check("open", open(devname2, O_RDWR), dev + 1);
	check("close", close(dev2), 0);

	printf("Defer close by driver handler\n");
	check("ioctl", ioctl(dev, RTTST_RTIOC_RTDM_DEFER_CLOSE,
			     RTTST_RTDM_DEFER_CLOSE_HANDLER), 0);
	start = rt_timer_tsc();
	check("close", close(dev), 0);
	check("open", open(devname, O_RDWR), -EBUSY);
	dev2 = check("open", open(devname2, O_RDWR), dev);
	check("close", close(dev2), 0);
	usleep(300000);
	dev = check("open", open(devname, O_RDWR), dev);

	printf("Defer close by pending reference\n");
	check("ioctl", ioctl(dev, RTTST_RTIOC_RTDM_DEFER_CLOSE,
			     RTTST_RTDM_DEFER_CLOSE_CONTEXT), 0);
	start = rt_timer_tsc();
	check("close", close(dev), 0);
	check("open", open(devname, O_RDWR), -EBUSY);
	dev2 = check("open", open(devname2, O_RDWR), dev);
	check("close", close(dev2), 0);
	usleep(300000);
	dev = check("open", open(devname, O_RDWR), dev);

	printf("Normal close\n");
	check("ioctl", ioctl(dev, RTTST_RTIOC_RTDM_DEFER_CLOSE,
			     RTTST_RTDM_NORMAL_CLOSE), 0);
	check("close", close(dev), 0);
	dev = check("open", open(devname, O_RDWR), dev);

	printf("Deferred module unload\n");
	check("ioctl", ioctl(dev, RTTST_RTIOC_RTDM_DEFER_CLOSE,
			     RTTST_RTDM_DEFER_CLOSE_CONTEXT), 0);
	start = rt_timer_tsc();
	check("close", close(dev), 0);
	check("rmmod", system("rmmod xeno_rtdmtest"), 0);
	check_sleep("rmmod", start);

	return 0;
}
Beispiel #5
0
void *cond_killer(void *cookie)
{
	unsigned long long start;
	struct cond_mutex *cm = cookie;

	start = rt_timer_tsc();
	check("mutex_lock", mutex_lock(cm->mutex), 0);
	check_sleep("mutex_lock", start);
	thread_msleep(10);
	check("thread_kill", thread_kill(cm->tid, SIGRTMIN), 0);
	check("mutex_unlock", mutex_unlock(cm->mutex), 0);

	return NULL;
}
Beispiel #6
0
void *cond_signaler(void *cookie)
{
	unsigned long long start;
	struct cond_mutex *cm = cookie;

	start = rt_timer_tsc();
	check("mutex_lock", mutex_lock(cm->mutex), 0);
	check_sleep("mutex_lock", start);
	thread_msleep(10);
	check("cond_signal", cond_signal(cm->cond), 0);
	check("mutex_unlock", mutex_unlock(cm->mutex), 0);

	return NULL;
}
Beispiel #7
0
static void *
add_my_node(int arg1, void *arg2) {
	int counter = 10;
	dbg(DBG_TEST, "Invoke add_mynode\n");

	int rand_number, i=0;	

	while (counter > 0) {
		check_sleep("add");
		kmutex_lock(&mynode.my_mutex);

		check_sleep("add");

		if (mynode.length < 5) {
			mynode.length++;
			counter--;
		}

		dbg(DBG_TEST, "Add node: %d\n", mynode.length);
		kmutex_unlock(&mynode.my_mutex);
	}
	
	return NULL;
}
Beispiel #8
0
void *cond_destroyer(void *cookie)
{
	unsigned long long start;
	struct cond_mutex *cm = cookie;

	start = rt_timer_tsc();
	check("mutex_lock", mutex_lock(cm->mutex), 0);
	check_sleep("mutex_lock", start);
	thread_msleep(10);
#ifdef XENO_POSIX
	check("cond_destroy", cond_destroy(cm->cond), -EBUSY);
#else /* native */
	check("cond_destroy", cond_destroy(cm->cond), 0);
#endif /* native */
	check("mutex_unlock", mutex_unlock(cm->mutex), 0);

	return NULL;
}
Beispiel #9
0
void absolute_condwait(void)
{
	unsigned long long start;
	mutex_t mutex;
	cond_t cond;

	fprintf(stderr, "%s\n", __FUNCTION__);

	check("mutex_init", mutex_init(&mutex, PTHREAD_MUTEX_DEFAULT, 0), 0);
	check("cond_init", cond_init(&cond, 1), 0);
	check("mutex_lock", mutex_lock(&mutex), 0);

	start = rt_timer_tsc();
	check("cond_wait",
	      cond_wait_until(&cond, &mutex, timer_read() + 10 * NS_PER_MS),
	      -ETIMEDOUT);
	check_sleep("cond_wait", start);

	check("mutex_unlock", mutex_unlock(&mutex), 0);
	check("mutex_destroy", mutex_destroy(&mutex), 0);
	check("cond_destroy", cond_destroy(&cond), 0);
}
Beispiel #10
0
void sig_norestart_double(void)
{
	unsigned long long start;
	mutex_t mutex;
	cond_t cond;
	struct cond_mutex cm = {
		.mutex = &mutex,
		.cond = &cond,
		.tid = thread_self(),
	};
	thread_t double_killer_tid;
	struct sigaction sa = {
		.sa_handler = sighandler,
		.sa_flags = 0,
	};
	sigemptyset(&sa.sa_mask);

	fprintf(stderr, "%s\n", __FUNCTION__);

	check_unix("sigaction", sigaction(SIGRTMIN, &sa, NULL), 0);
	check("mutex_init", mutex_init(&mutex, PTHREAD_MUTEX_DEFAULT, 0), 0);
	check("cond_init", cond_init(&cond, 0), 0);
	check("mutex_lock", mutex_lock(&mutex), 0);
	check("thread_spawn",
	      thread_spawn(&double_killer_tid, 2, double_killer, &cm), 0);
	thread_msleep(11);

	sig_seen = 0;
	start = rt_timer_tsc();
	check("cond_wait", cond_wait(&cond, &mutex, XN_INFINITE), 0);
	check_sleep("cond_wait", start);
	check("sig_seen", sig_seen, 2);
	thread_msleep(10);

	check("mutex_unlock", mutex_unlock(&mutex), 0);
	check("thread_join", thread_join(double_killer_tid), 0);
	check("mutex_destroy", mutex_destroy(&mutex), 0);
	check("cond_destroy", cond_destroy(&cond), 0);
}

void sig_restart_double(void)
{
	unsigned long long start;
	mutex_t mutex;
	cond_t cond;
	struct cond_mutex cm = {
		.mutex = &mutex,
		.cond = &cond,
		.tid = thread_self(),
	};
	thread_t double_killer_tid;
	struct sigaction sa = {
		.sa_handler = sighandler,
		.sa_flags = SA_RESTART,
	};
	sigemptyset(&sa.sa_mask);

	fprintf(stderr, "%s\n", __FUNCTION__);

	check_unix("sigaction", sigaction(SIGRTMIN, &sa, NULL), 0);
	check("mutex_init", mutex_init(&mutex, PTHREAD_MUTEX_DEFAULT, 0), 0);
	check("cond_init", cond_init(&cond, 0), 0);
	check("mutex_lock", mutex_lock(&mutex), 0);
	check("thread_spawn",
	      thread_spawn(&double_killer_tid, 2, double_killer, &cm), 0);
	thread_msleep(11);

	sig_seen = 0;
	start = rt_timer_tsc();

	check("cond_wait", cond_wait(&cond, &mutex, XN_INFINITE), 0);
	check_sleep("cond_wait", start);
	check("sig_seen", sig_seen, 2);
	thread_msleep(10);

	check("mutex_unlock", mutex_unlock(&mutex), 0);
	check("thread_join", thread_join(double_killer_tid), 0);
	check("mutex_destroy", mutex_destroy(&mutex), 0);
	check("cond_destroy", cond_destroy(&cond), 0);
}
Beispiel #11
0
void sig_norestart_condwait(void)
{
	unsigned long long start;
	mutex_t mutex;
	cond_t cond;
	struct cond_mutex cm = {
		.mutex = &mutex,
		.cond = &cond,
		.tid = thread_self(),
	};
	thread_t cond_killer_tid;
	struct sigaction sa = {
		.sa_handler = sighandler,
		.sa_flags = 0,
	};
	sigemptyset(&sa.sa_mask);

	fprintf(stderr, "%s\n", __FUNCTION__);

	check_unix("sigaction", sigaction(SIGRTMIN, &sa, NULL), 0);
	check("mutex_init", mutex_init(&mutex, PTHREAD_MUTEX_DEFAULT, 0), 0);
	check("cond_init", cond_init(&cond, 0), 0);
	check("mutex_lock", mutex_lock(&mutex), 0);
	check("thread_spawn",
	      thread_spawn(&cond_killer_tid, 2, cond_killer, &cm), 0);
	thread_msleep(11);

	start = rt_timer_tsc();
	sig_seen = 0;
#ifdef XENO_POSIX
	check("cond_wait", cond_wait(&cond, &mutex, XN_INFINITE), 0);
#else /* native */
	{
		int err = cond_wait(&cond, &mutex, XN_INFINITE);
		if (err == 0)
			err = -EINTR;
		check("cond_wait", err, -EINTR);
	}
#endif /* native */
	check_sleep("cond_wait", start);
	check("sig_seen", sig_seen, 1);
	check("mutex_unlock", mutex_unlock(&mutex), 0);
	check("thread_join", thread_join(cond_killer_tid), 0);
	check("mutex_destroy", mutex_destroy(&mutex), 0);
	check("cond_destroy", cond_destroy(&cond), 0);
}

void sig_restart_condwait(void)
{
	unsigned long long start;
	mutex_t mutex;
	cond_t cond;
	struct cond_mutex cm = {
		.mutex = &mutex,
		.cond = &cond,
		.tid = thread_self(),
	};
	thread_t cond_killer_tid;
	struct sigaction sa = {
		.sa_handler = sighandler,
		.sa_flags = 0,
	};
	sigemptyset(&sa.sa_mask);

	fprintf(stderr, "%s\n", __FUNCTION__);

	check_unix("sigaction", sigaction(SIGRTMIN, &sa, NULL), 0);
	check("mutex_init", mutex_init(&mutex, PTHREAD_MUTEX_DEFAULT, 0), 0);
	check("cond_init", cond_init(&cond, 0), 0);
	check("mutex_lock", mutex_lock(&mutex), 0);
	check("thread_spawn",
	      thread_spawn(&cond_killer_tid, 2, cond_killer, &cm), 0);
	thread_msleep(11);

	start = rt_timer_tsc();
	sig_seen = 0;
#ifdef XENO_POSIX
	check("cond_wait", cond_wait(&cond, &mutex, XN_INFINITE), 0);
#else /* native */
	{
		int err = cond_wait(&cond, &mutex, XN_INFINITE);
		if (err == 0)
			err = -EINTR;
		check("cond_wait", err, -EINTR);
	}
#endif /* native */
	check_sleep("cond_wait", start);
	check("sig_seen", sig_seen, 1);
	check("mutex_unlock", mutex_unlock(&mutex), 0);
	check("thread_join", thread_join(cond_killer_tid), 0);
	check("mutex_destroy", mutex_destroy(&mutex), 0);
	check("cond_destroy", cond_destroy(&cond), 0);
}

void *mutex_killer(void *cookie)
{
	unsigned long long start;
	struct cond_mutex *cm = cookie;

	start = rt_timer_tsc();
	check("mutex_lock", mutex_lock(cm->mutex), 0);
	check_sleep("mutex_lock", start);
	check("cond_signal", cond_signal(cm->cond), 0);
	thread_msleep(10);
	check("thread_kill", thread_kill(cm->tid, SIGRTMIN), 0);
	check("mutex_unlock", mutex_unlock(cm->mutex), 0);

	return NULL;
}
Beispiel #12
0
int main (int argc, char **argv)
{
	if (argc == 2) {
		if (strncmp(argv[1], "-v", 2) == 0) {
			__android_log_write(ANDROID_LOG_ERROR, APPNAME, "Getting ILWT OCD version");
			printf(APPVERSION);
		}	
	}
	else {
	  ocConfig  conf;
	  pid_t pid, sid;
	  char input_buffer[9];
	  int asleep = 0;
	  int charging = 0;
	  int low_batt = 0;
	  int hot_batt = 0;
	  
	  __android_log_write(ANDROID_LOG_INFO, APPNAME, "Starting service.");
	  if (load_config(&conf) == -1){
		if (configFile == 0) {
			configFile = 1;
			if (load_config(&conf) == -1) {
				__android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to load configuration. Stopping.");
				return 1;
			}
		}
		else {
			__android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to load configuration. Stopping.");
			return 1;
		}
	  }

          //IOSCHED-CHANGE - start
          ioSchedConfig io_config;
          if(load_iosched_config(&io_config) == -1){
              if(io_configFile == 0) {
                  io_configFile = 1;
                  if(load_iosched_config(&io_config) == -1){
                      __android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to load io configuration. Stopping.");
                      return 1;
                  }
              } else {
                  __android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to load io configuration. Stopping.");
                  return 1;
              }
          }
          //IOSCHED-CHANGE - end

	  
	  input_buffer[0] = 0;
		
	  pid = fork();
	  if (pid < 0)
		exit(2);
	  if (pid > 0)
		exit(0);
	  umask(0);
	  
	  sid = setsid();
	  if (sid < 0)
		exit(2);
	  if ((chdir("/")) < 0)
		exit(2);
	  close(STDIN_FILENO);
	  close(STDOUT_FILENO);
	  close(STDERR_FILENO);

          //IOSCHED-CHANGE
          set_io_sched_params(io_config.io_scheduler);
	  
	  char* my_governor = conf.wake_governor;
	  char* my_min_freq = conf.wake_min_freq;
	  char* my_max_freq = conf.wake_max_freq;
	  
	  input_buffer[0] = '\0';
	  
	  if (read_from_file(SYS_WAKE, 6, input_buffer) == -1)
	  {                  
		__android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to get data from file. Cannot continue.");
		return 1;
	  }
	  if (strcmp(input_buffer, "awake") == 0)
	  {
		__android_log_write(ANDROID_LOG_INFO, APPNAME, "Setting awake profile for boot sequence.");
		set_cpu_params(my_governor, my_min_freq, my_max_freq);
	  }

	  while (1)
	  {
		asleep = check_sleep();
		
		if (asleep == 2)
		{
		  __android_log_write(ANDROID_LOG_INFO, APPNAME, "Setting sleep profile.");
		  set_cpu_params(conf.sleep_governor, conf.sleep_min_freq, conf.sleep_max_freq);
		}
		else if (asleep == 1)
		{
			__android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to get data from file. Cannot continue.");
			return 1;
		}
	  
		input_buffer[0] = '\0';
	  
		if (read_from_file(SYS_WAKE, 6, input_buffer) == -1) {                  
		  __android_log_write(ANDROID_LOG_ERROR, APPNAME, "Unable to get data from file. Cannot continue.");
		  return 1;
		}
		if (strcmp(input_buffer, "awake") == 0)
		{
			hot_batt = check_batt_temp(atoi(conf.battery_temp));
		
			if (hot_batt == 2) {
				__android_log_write(ANDROID_LOG_INFO, APPNAME, "Setting heat profile.");
				my_governor = conf.battery_temp_governor;
				my_min_freq = conf.battery_temp_min_freq;
				my_max_freq = conf.battery_temp_max_freq;
			}
			else {
				charging = check_charge();
				if (charging == 2) {
					__android_log_write(ANDROID_LOG_INFO, APPNAME, "Setting charge profile.");
					my_governor = conf.charge_governor;
					my_min_freq = conf.charge_min_freq;
					my_max_freq = conf.charge_max_freq;
				}
				else {
					low_batt = check_batt_cap(atoi(conf.battery_cap));
					
					if (low_batt == 2) {
						__android_log_write(ANDROID_LOG_INFO, APPNAME, "Setting capacity profile.");
						my_governor = conf.battery_cap_governor;
						my_min_freq = conf.battery_cap_min_freq;
						my_max_freq = conf.battery_cap_max_freq;
					}
					else {
						__android_log_write(ANDROID_LOG_INFO, APPNAME, "Setting awake profile.");
						my_governor = conf.wake_governor;
						my_min_freq = conf.wake_min_freq;
						my_max_freq = conf.wake_max_freq;
					}
				}
			}
				
			set_cpu_params(my_governor, my_min_freq, my_max_freq);
		}
	  }
  }
 
  return 0;
}