/** @brief The LKM initialization function * The static keyword restricts the visibility of the function to within this C file. The __init * macro means that for a built-in driver (not a LKM) the function is only used at initialization * time and that it can be discarded and its memory freed up after that point. In this example this * function sets up the GPIOs and the IRQ * @return returns 0 if successful */ static int __init ebbButton_init (void) { int result = 0; unsigned long IRQflags = IRQF_TRIGGER_RISING; // The default is a rising-edge interrupt printk(KERN_INFO "EBB Button: Initializing the EBB Button LKM\n"); sprintf(gpioName, "gpio%d", pressDetectInp); // Create the gpio115 name for /sys/ebb/gpio115 // create the kobject sysfs entry at /sys/ebb -- probably not an ideal location! ebb_kobj = kobject_create_and_add("ebb", kernel_kobj->parent); // kernel_kobj points to /sys/kernel if (!ebb_kobj) { printk(KERN_ALERT "EBB Button: failed to create kobject mapping\n"); return -ENOMEM; } // add the attributes to /sys/ebb/ -- for example, /sys/ebb/gpio115/numberPresses result = sysfs_create_group(ebb_kobj, &attr_group); if (result) { printk(KERN_ALERT "EBB Button: failed to create sysfs group\n"); kobject_put(ebb_kobj); // clean up -- remove the kobject sysfs entry return result; } getnstimeofday(&ts_last); // set the last time to be the current time ts_diff = timespec_sub(ts_last, ts_last); // set the initial time difference to be 0 // Set button outputs. It is a GPIO in input mode result = gpio_request_array(btn_gpios, ARRAY_SIZE(btn_gpios)); if (result) { printk(KERN_ALERT "EBB Button: failed to request input array\n"); return result; } // Perform a quick test to see that the button is working as expected on LKM load printk(KERN_INFO "EBB Button: The button state is currently: %d\n", gpio_get_value(pressDetectInp)); /// GPIO numbers and IRQ numbers are not the same! This function performs the mapping for us irqNumber = gpio_to_irq(pressDetectInp); printk(KERN_INFO "EBB Button: The button is mapped to IRQ: %d\n", irqNumber); if (!isRising) // If the kernel parameter isRising=0 is supplied { IRQflags = IRQF_TRIGGER_FALLING; // Set the interrupt to be on the falling edge } // This next call requests an interrupt line result = request_irq(irqNumber, // The interrupt number requested (irq_handler_t) ebbgpio_irq_handler, // The pointer to the handler function below IRQflags, // Use the custom kernel param to set interrupt type "ebb_button_handler", // Used in /proc/interrupts to identify the owner NULL); // The *dev_id for shared interrupt lines, NULL is okay return result; }
static int update_cycles(struct reg_cycle_t * prev_cycle, struct reg_cycle_t * cur_cycle, ssize_t cur_qlen, bool enqueue) { ssize_t end_len; struct timespec t_sub; s64 t_sub_ns; end_len = 0; if (!enqueue) { if (!cur_qlen) return -1; end_len = 1; } else if (cur_qlen == end_len) { /* end cycle */ getnstimeofday(&cur_cycle->t_end); t_sub = timespec_sub(cur_cycle->t_end, cur_cycle->t_last_start); cur_cycle->sum_area += (ulong) cur_qlen * timespec_to_ns(&t_sub); cur_cycle->t_last_start = cur_cycle->t_end; } else { /* middle cycle */ cur_cycle->t_last_start = cur_cycle->t_end; getnstimeofday(&cur_cycle->t_end); t_sub = timespec_sub(cur_cycle->t_end, cur_cycle->t_last_start); cur_cycle->sum_area +=(ulong) cur_qlen * timespec_to_ns(&t_sub); } t_sub = timespec_sub(cur_cycle->t_end, prev_cycle->t_start); t_sub_ns = timespec_to_ns(&t_sub); cur_cycle->avg_len = (cur_cycle->sum_area + prev_cycle->sum_area); if (t_sub_ns <= 0) { LOG_ERR("Time delta is <= 0!"); return -1; } cur_cycle->avg_len /= (ulong) abs(t_sub_ns); return 0; }
/** * omap3_enter_idle - Programs OMAP3 to enter the specified state * @dev: cpuidle device * @state: The target state to be programmed * * Called from the CPUidle framework to program the device to the * specified target state selected by the governor. */ static int omap3_enter_idle(struct cpuidle_device *dev, struct cpuidle_state *state) { struct omap3_processor_cx *cx = cpuidle_get_statedata(state); struct timespec ts_preidle, ts_postidle, ts_idle; u32 mpu_state = cx->mpu_state, core_state = cx->core_state; u32 saved_mpu_state; current_cx_state = *cx; /* Used to keep track of the total time in idle */ getnstimeofday(&ts_preidle); local_irq_disable(); local_fiq_disable(); if (!enable_off_mode) { if (mpu_state < PWRDM_POWER_RET) mpu_state = PWRDM_POWER_RET; if (core_state < PWRDM_POWER_RET) core_state = PWRDM_POWER_RET; } if (omap_irq_pending() || need_resched()) goto return_sleep_time; saved_mpu_state = pwrdm_read_next_pwrst(mpu_pd); pwrdm_set_next_pwrst(mpu_pd, mpu_state); pwrdm_set_next_pwrst(core_pd, core_state); if (cx->type == OMAP3_STATE_C1) { pwrdm_for_each_clkdm(mpu_pd, _cpuidle_deny_idle); pwrdm_for_each_clkdm(core_pd, _cpuidle_deny_idle); } /* Execute ARM wfi */ omap_sram_idle(); if (cx->type == OMAP3_STATE_C1) { pwrdm_for_each_clkdm(mpu_pd, _cpuidle_allow_idle); pwrdm_for_each_clkdm(core_pd, _cpuidle_allow_idle); } pwrdm_set_next_pwrst(mpu_pd, saved_mpu_state); return_sleep_time: getnstimeofday(&ts_postidle); ts_idle = timespec_sub(ts_postidle, ts_preidle); local_irq_enable(); local_fiq_enable(); return ts_idle.tv_nsec / NSEC_PER_USEC + ts_idle.tv_sec * USEC_PER_SEC; }
/** * _omap_device_activate - increase device readiness * @od: struct omap_device * * @ignore_lat: increase to latency target (0) or full readiness (1)? * * Increase readiness of omap_device @od (thus decreasing device * wakeup latency, but consuming more power). If @ignore_lat is * IGNORE_WAKEUP_LAT, make the omap_device fully active. Otherwise, * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup * latency is greater than the requested maximum wakeup latency, step * backwards in the omap_device_pm_latency table to ensure the * device's maximum wakeup latency is less than or equal to the * requested maximum wakeup latency. Returns 0. */ static int _omap_device_activate(struct omap_device *od, u8 ignore_lat) { struct timespec a, b, c; pr_debug("omap_device: %s: activating\n", od->pdev.name); while (od->pm_lat_level > 0) { struct omap_device_pm_latency *odpl; unsigned long long act_lat = 0; od->pm_lat_level--; odpl = od->pm_lats + od->pm_lat_level; if (!ignore_lat && (od->dev_wakeup_lat <= od->_dev_wakeup_lat_limit)) break; read_persistent_clock(&a); /* XXX check return code */ odpl->activate_func(od); read_persistent_clock(&b); c = timespec_sub(b, a); act_lat = timespec_to_ns(&c); pr_debug("omap_device: %s: pm_lat %d: activate: elapsed time " "%llu nsec\n", od->pdev.name, od->pm_lat_level, act_lat); if (act_lat > odpl->activate_lat) { odpl->activate_lat_worst = act_lat; if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) { odpl->activate_lat = act_lat; pr_debug("omap_device: %s.%d: new worst case " "activate latency %d: %llu\n", od->pdev.name, od->pdev.id, od->pm_lat_level, act_lat); } else pr_debug("omap_device: %s.%d: activate " "latency %d higher than exptected. " "(%llu > %d)\n", od->pdev.name, od->pdev.id, od->pm_lat_level, act_lat, odpl->activate_lat); } od->dev_wakeup_lat -= odpl->activate_lat; } return 0; }
static char * get_time (void) { struct timespec TV2 = timespec_sub (current_timespec (), TV1); uintmax_t s = TV2.tv_sec; int ns = TV2.tv_nsec; if (watch_not_started) exit (EXIT_FAILURE); /* call reset_watch first ! */ sprintf (time_string, "%"PRIuMAX".%0*d", s, LOG10_TIMESPEC_RESOLUTION, ns); return time_string; }
static void print_result(u32 xfer_size, struct timespec lhs, struct timespec rhs) { long us; struct timespec ts; ts = timespec_sub(rhs, lhs); us = ts.tv_sec*USEC_PER_SEC + ts.tv_nsec/NSEC_PER_USEC; printk(KERN_INFO "%u: %lu\n", xfer_size, us); }
static unsigned long omap3epfb_calc_latency(struct omap3epfb_par *par, int dest, int end) { BUG_ON(end < UPD_PRE_BLITTER || end > UPD_DSS_STARTING); BUG_ON(dest < UPD_PB_LATENCY || dest > UPD_FULL_LATENCY); par->update_timings[dest] = timespec_sub(par->update_timings[end], par->update_timings[UPD_APP_REQUEST]); return (par->update_timings[dest].tv_sec * 1000000 + (par->update_timings[dest].tv_nsec / 1000)); }
/** * _omap_device_deactivate - decrease device readiness * @od: struct omap_device * * @ignore_lat: decrease to latency target (0) or full inactivity (1)? * * Decrease readiness of omap_device @od (thus increasing device * wakeup latency, but conserving power). If @ignore_lat is * IGNORE_WAKEUP_LAT, make the omap_device fully inactive. Otherwise, * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup * latency is less than the requested maximum wakeup latency, step * forwards in the omap_device_pm_latency table to ensure the device's * maximum wakeup latency is less than or equal to the requested * maximum wakeup latency. Returns 0. */ static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat) { struct timespec a, b, c; dev_dbg(&od->pdev->dev, "omap_device: deactivating\n"); while (od->pm_lat_level < od->pm_lats_cnt) { struct omap_device_pm_latency *odpl; unsigned long long deact_lat = 0; odpl = od->pm_lats + od->pm_lat_level; if (!ignore_lat && ((od->dev_wakeup_lat + odpl->activate_lat) > od->_dev_wakeup_lat_limit)) break; read_persistent_clock(&a); /* XXX check return code */ odpl->deactivate_func(od); read_persistent_clock(&b); c = timespec_sub(b, a); deact_lat = timespec_to_ns(&c); dev_dbg(&od->pdev->dev, "omap_device: pm_lat %d: deactivate: elapsed time " "%llu nsec\n", od->pm_lat_level, deact_lat); if (deact_lat > odpl->deactivate_lat) { odpl->deactivate_lat_worst = deact_lat; if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) { odpl->deactivate_lat = deact_lat; dev_dbg(&od->pdev->dev, "new worst case deactivate latency " "%d: %llu\n", od->pm_lat_level, deact_lat); } else dev_warn(&od->pdev->dev, "deactivate latency %d " "higher than exptected. (%llu > %d)\n", od->pm_lat_level, deact_lat, odpl->deactivate_lat); } od->dev_wakeup_lat += odpl->activate_lat; od->pm_lat_level++; } return 0; }
void bye(void) { clock_gettime(CLOCK_THREAD_CPUTIME_ID, &task_rst.t_whole_thread_finish); task_rst.t_whole_thread_run = timespec_sub(&task_rst.t_whole_thread_finish, &task_rst.t_whole_thread_start); printf("thread_total= %lld ns\t%3.2f%%\t%3.2f%%\nthread_run= %lld ns\t%3.2f%%\t%3.2f%%\n===end===\n", timespec_to_nsec(&task_rst.t_whole_thread_finish), (double)timespec_to_nsec(&task_rst.t_whole_thread_finish) / (double)timespec_to_nsec(&task_rst.dl_budget) / (double)task_rst.correct_cnt * 100.0, (double)timespec_to_nsec(&task_rst.t_whole_thread_finish) / (double)timespec_to_nsec(&task_rst.dl_period) / (double)task_rst.correct_cnt * 100.0, timespec_to_nsec(&task_rst.t_whole_thread_run), (double)timespec_to_nsec(&task_rst.t_whole_thread_run) / (double)timespec_to_nsec(&task_rst.dl_budget) / (double)task_rst.correct_cnt * 100.0, (double)timespec_to_nsec(&task_rst.t_whole_thread_run) / (double)timespec_to_nsec(&task_rst.dl_period) / (double)task_rst.correct_cnt * 100.0); }
static unsigned long long calibrate(void) { struct timespec start, end, delta; const int crunch_loops = 10000; unsigned long long ns, lps; unsigned long count; struct timespec req; char label[8]; int n; count = 0; clock_gettime(CLOCK_MONOTONIC, &start); do_work(crunch_loops, &count); clock_gettime(CLOCK_MONOTONIC, &end); timespec_sub(&delta, &end, &start); ns = delta.tv_sec * ONE_BILLION + delta.tv_nsec; crunch_per_sec = (unsigned long long)((double)ONE_BILLION / (double)ns * crunch_loops); for (n = 0; n < nrthreads; n++) { sprintf(label, "t%d", n); create_fifo_thread(threads[n], label, counts[n]); sem_wait(&ready); } pthread_mutex_lock(&lock); started = 1; pthread_cond_broadcast(&barrier); pthread_mutex_unlock(&lock); req.tv_sec = 1; req.tv_nsec = 0; clock_nanosleep(CLOCK_MONOTONIC, 0, &req, NULL); for (n = 0, lps = 0; n < nrthreads; n++) { lps += counts[n]; pthread_kill(threads[n], SIGDEMT); } atomic_set(&throttle, 1); smp_wmb(); for (n = 0; n < nrthreads; n++) { pthread_cancel(threads[n]); pthread_join(threads[n], NULL); } started = 0; atomic_set(&throttle, 0); return lps; }
// ------------------------------------------------------------------------------ // Write Heartbeat message // ------------------------------------------------------------------------------ void Autopilot_Interface:: write_heartbeat() { // -------------------------------------------------------------------------- // PACK PAYLOAD // -------------------------------------------------------------------------- // Allocate Space mavlink_message_t msg; mavlink_heartbeat_t heartbeat; struct timespec t_now_rt,t_diff_rt; uint64_t timestamp = get_time_usec(); // Pack the message //mavlink_msg_heartbeat_pack(system_id, companion_id, &msg, mav_type, autopilot_id , base_mode, custom_mode, system_status) heartbeat.type = MAV_TYPE_GCS; heartbeat.autopilot = autopilot_id; heartbeat.base_mode = base_mode; heartbeat.system_status = system_status; heartbeat.custom_mode = 0; mavlink_msg_heartbeat_encode(system_id, companion_id, &msg, &heartbeat); //mavlink_msg_heartbeat_encode(2, 125, &msg, &heartbeat); // -------------------------------------------------------------------------- // WRITE // -------------------------------------------------------------------------- clock_gettime(CLOCK_REALTIME,&t_now_rt); int len = write_message(msg); timespec_sub(&t_diff_rt,&t_now_rt,&t_wrold_rt); int64_t diff_rt = t_diff_rt.tv_sec*1e6 + t_diff_rt.tv_nsec/1e3; //clock_gettime(CLOCK_REALTIME,&t_wrold_rt); // With this command I obtained a DT with the writing time in the computation t_wrold_rt.tv_nsec = t_now_rt.tv_nsec; t_wrold_rt.tv_sec = t_now_rt.tv_sec; //printf("hil_sensors_t DT : %lu us\r",diff_rt); // check the write if ( not len > 0 ) fprintf(stderr,"WARNING: could not send HIL_SENSORS \n"); // else // printf("%lu POSITION_TARGET = [ %f , %f , %f ] \n", write_count, position_target.x, position_target.y, position_target.z); return; }
struct timespec cal_dmaci_ampdu(int t){ struct timespec transmit={0},tmp1={0},tmp2={0},difs={0},dmaci={0}; ampdu[t].th = ampdu[t].tw; if (timespec_compare(&du[t].th,&du[t].last_te)<0){ ampdu[t].th=ampdu[t].last_te; } transmit = cal_transmit_time(ampdu[t].len*ampdu[t].num,ampdu[t].rate); difs.tv_sec =0; difs.tv_nsec = CONST_TIME[t]*1000; tmp1 = timespec_sub(ampdu[t].te,ampdu[t].th); tmp2 = timespec_sub(tmp1,transmit); dmaci = timespec_sub(tmp2,difs); struct timespec ts_tmp; getnstimeofday(&ts_tmp); //checkpoint if (dmaci.tv_sec < 0 || dmaci.tv_nsec < 0){ dmaci.tv_sec = 0; dmaci.tv_nsec = 0; } return dmaci; }
/** * @brief Kernel module interrupt handler * Changes the button level when a button * is pressed. Also it puts limits on the level. * * @param irq The irq number that identifies the button * @return returns IRQ_HANDLED which tells the kernel that this is a non-fatal interrupt */ static irq_handler_t kcylon_irq_handler(unsigned int irq, void *dev_id, struct pt_regs *regs) { mutex_lock(&button_level_mutex); button_level += button_direction; if (button_level == 10 || button_level == -10) button_direction *= -1; mutex_unlock(&button_level_mutex); getnstimeofday(&ts_current); ts_diff = timespec_sub(ts_current, ts_last); ts_last = ts_current; printk(KERN_INFO "KCYLON: Interrupt received (button level %d)\n", button_level); return (irq_handler_t) IRQ_HANDLED; }
static void suspend_time_syscore_resume(void) { struct timespec after; read_persistent_clock(&after); after = timespec_sub(after, suspend_time_before); time_in_suspend_bins[fls(after.tv_sec)]++; pr_info("Suspended for %lu.%03lu seconds\n", after.tv_sec, after.tv_nsec / NSEC_PER_MSEC); }
/* Conversion from CLOCK_COPPERPLATE to clk_id. */ void clockobj_convert_clocks(struct clockobj *clkobj, const struct timespec *in, clockid_t clk_id, struct timespec *out) { struct timespec now, delta; __RT(clock_gettime(CLOCK_COPPERPLATE, &now)); /* Offset from CLOCK_COPPERPLATE epoch. */ timespec_sub(&delta, in, &now); /* Current time for clk_id. */ __RT(clock_gettime(clk_id, &now)); /* Absolute timeout again, clk_id-based this time. */ timespec_add(out, &delta, &now); }
/* * Process a single command. */ static int cmd_dispatch(char *cmd) { struct timespec before, after, duration; char *args[MAXMENUARGS]; int nargs=0; char *word; char *context; int i, result; for (word = strtok_r(cmd, " \t", &context); word != NULL; word = strtok_r(NULL, " \t", &context)) { if (nargs >= MAXMENUARGS) { kprintf("Command line has too many words\n"); return E2BIG; } args[nargs++] = word; } if (nargs==0) { return 0; } for (i=0; cmdtable[i].name; i++) { if (*cmdtable[i].name && !strcmp(args[0], cmdtable[i].name)) { KASSERT(cmdtable[i].func!=NULL); gettime(&before); result = cmdtable[i].func(nargs, args); gettime(&after); timespec_sub(&after, &before, &duration); kprintf("Operation took %llu.%09lu seconds\n", (unsigned long long) duration.tv_sec, (unsigned long) duration.tv_nsec); return result; } } kprintf("%s: Command not found\n", args[0]); return EINVAL; }
/* Get current value of timer TIMERID and store it in VLAUE. */ int timer_gettime (timer_t timerid, struct itimerspec *value) { struct timer_node *timer; struct timespec now, expiry; int retval = -1, armed = 0, valid; clock_t clock = 0; pthread_mutex_lock (&__timer_mutex); timer = timer_id2ptr (timerid); valid = timer_valid (timer); if (valid) { armed = timer->armed; expiry = timer->expirytime; clock = timer->clock; value->it_interval = timer->value.it_interval; } pthread_mutex_unlock (&__timer_mutex); if (valid) { if (armed) { clock_gettime (clock, &now); if (timespec_compare (&now, &expiry) < 0) timespec_sub (&value->it_value, &expiry, &now); else { value->it_value.tv_sec = 0; value->it_value.tv_nsec = 0; } } else { value->it_value.tv_sec = 0; value->it_value.tv_nsec = 0; } retval = 0; } else __set_errno (EINVAL); return retval; }
void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk) { const struct cred *tcred; struct timespec uptime, ts; u64 ac_etime; BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN); do_posix_clock_monotonic_gettime(&uptime); ts = timespec_sub(uptime, tsk->start_time); ac_etime = timespec_to_ns(&ts); do_div(ac_etime, NSEC_PER_USEC); stats->ac_etime = ac_etime; stats->ac_btime = get_seconds() - ts.tv_sec; if (thread_group_leader(tsk)) { stats->ac_exitcode = tsk->exit_code; if (tsk->flags & PF_FORKNOEXEC) stats->ac_flag |= AFORK; } if (tsk->flags & PF_SUPERPRIV) stats->ac_flag |= ASU; if (tsk->flags & PF_DUMPCORE) stats->ac_flag |= ACORE; if (tsk->flags & PF_SIGNALED) stats->ac_flag |= AXSIG; stats->ac_nice = task_nice(tsk); stats->ac_sched = tsk->policy; stats->ac_pid = tsk->pid; rcu_read_lock(); tcred = __task_cred(tsk); stats->ac_uid = tcred->uid; stats->ac_gid = tcred->gid; stats->ac_ppid = pid_alive(tsk) ? rcu_dereference(tsk->real_parent)->tgid : 0; rcu_read_unlock(); stats->ac_utime = cputime_to_msecs(tsk->utime) * USEC_PER_MSEC; stats->ac_stime = cputime_to_msecs(tsk->stime) * USEC_PER_MSEC; stats->ac_utimescaled = cputime_to_msecs(tsk->utimescaled) * USEC_PER_MSEC; stats->ac_stimescaled = cputime_to_msecs(tsk->stimescaled) * USEC_PER_MSEC; stats->ac_minflt = tsk->min_flt; stats->ac_majflt = tsk->maj_flt; strncpy(stats->ac_comm, tsk->comm, sizeof(stats->ac_comm)); }
static void set_alarm (void) { if (atimers) { #ifdef HAVE_SETITIMER struct itimerval it; #endif struct timespec now, interval; #ifdef HAVE_ITIMERSPEC if (0 <= timerfd || alarm_timer_ok) { struct itimerspec ispec; ispec.it_value = atimers->expiration; ispec.it_interval.tv_sec = ispec.it_interval.tv_nsec = 0; # ifdef HAVE_TIMERFD if (timerfd_settime (timerfd, TFD_TIMER_ABSTIME, &ispec, 0) == 0) { add_timer_wait_descriptor (timerfd); return; } # endif if (alarm_timer_ok && timer_settime (alarm_timer, TIMER_ABSTIME, &ispec, 0) == 0) return; } #endif /* Determine interval till the next timer is ripe. Don't set the interval to 0; this disables the timer. */ now = current_timespec (); interval = (timespec_cmp (atimers->expiration, now) <= 0 ? make_timespec (0, 1000 * 1000) : timespec_sub (atimers->expiration, now)); #ifdef HAVE_SETITIMER memset (&it, 0, sizeof it); it.it_value = make_timeval (interval); setitimer (ITIMER_REAL, &it, 0); #else /* not HAVE_SETITIMER */ alarm (max (interval.tv_sec, 1)); #endif /* not HAVE_SETITIMER */ } }
static int cvtestthread(void *junk, unsigned long num) { int i; volatile int j; struct timespec ts1, ts2; (void)junk; for (i=0; i<NCVLOOPS; i++) { lock_acquire(testlock); while (testval1 != num) { gettime(&ts1); cv_wait(testcv, testlock); gettime(&ts2); /* ts2 -= ts1 */ timespec_sub(&ts2, &ts1, &ts2); /* Require at least 2000 cpu cycles (we're 25mhz) */ if (ts2.tv_sec == 0 && ts2.tv_nsec < 40*2000) { kprintf("cv_wait took only %u ns\n", ts2.tv_nsec); kprintf("That's too fast... you must be " "busy-looping\n"); V(donesem); thread_exit(0); } } kprintf("Thread %lu\n", num); testval1 = (testval1 + NTHREADS - 1)%NTHREADS; /* * loop a little while to make sure we can measure the * time waiting on the cv. */ for (j=0; j<3000; j++); cv_broadcast(testcv, testlock); lock_release(testlock); } V(donesem); return 0; }
static void omap2_enter_mpu_retention(void) { int only_idle = 0; struct timespec ts_preidle, ts_postidle, ts_idle; /* Putting MPU into the WFI state while a transfer is active * seems to cause the I2C block to timeout. Why? Good question. */ if (omap2_i2c_active()) return; /* The peripherals seem not to be able to wake up the MPU when * it is in retention mode. */ if (omap2_allow_mpu_retention()) { /* REVISIT: These write to reserved bits? */ omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, PM_WKST1); omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP24XX_PM_WKST2); omap2_prm_write_mod_reg(0xffffffff, WKUP_MOD, PM_WKST); /* Try to enter MPU retention */ omap2_prm_write_mod_reg((0x01 << OMAP_POWERSTATE_SHIFT) | OMAP_LOGICRETSTATE_MASK, MPU_MOD, OMAP2_PM_PWSTCTRL); } else { /* Block MPU retention */ omap2_prm_write_mod_reg(OMAP_LOGICRETSTATE_MASK, MPU_MOD, OMAP2_PM_PWSTCTRL); only_idle = 1; } if (omap2_pm_debug) { omap2_pm_dump(only_idle ? 2 : 1, 0, 0); getnstimeofday(&ts_preidle); } omap2_sram_idle(); if (omap2_pm_debug) { unsigned long long tmp; getnstimeofday(&ts_postidle); ts_idle = timespec_sub(ts_postidle, ts_preidle); tmp = timespec_to_ns(&ts_idle) * NSEC_PER_USEC; omap2_pm_dump(only_idle ? 2 : 1, 1, tmp); } }
/** * omap3_enter_idle - Programs OMAP3 to enter the specified state * @dev: cpuidle device * @state: The target state to be programmed * * Called from the CPUidle framework to program the device to the * specified target state selected by the governor. */ static int omap3_enter_idle(struct cpuidle_device *dev, struct cpuidle_state *state) { struct omap3_processor_cx *cx = cpuidle_get_statedata(state); struct timespec ts_preidle, ts_postidle, ts_idle; u32 mpu_state = cx->mpu_state, core_state = cx->core_state; current_cx_state = *cx; /* Used to keep track of the total time in idle */ getnstimeofday(&ts_preidle); local_irq_disable(); local_fiq_disable(); pwrdm_set_next_pwrst(mpu_pd, mpu_state); pwrdm_set_next_pwrst(core_pd, core_state); //&*&*&*BC1_110630: add cpu idle control flag if (omap_irq_pending() || need_resched() || omap3_idle_bm_check()) goto return_sleep_time; //&*&*&*BC2_110630: add cpu idle control flag if (cx->type == OMAP3_STATE_C1) { pwrdm_for_each_clkdm(mpu_pd, _cpuidle_deny_idle); pwrdm_for_each_clkdm(core_pd, _cpuidle_deny_idle); } /* Execute ARM wfi */ omap_sram_idle(); if (cx->type == OMAP3_STATE_C1) { pwrdm_for_each_clkdm(mpu_pd, _cpuidle_allow_idle); pwrdm_for_each_clkdm(core_pd, _cpuidle_allow_idle); } return_sleep_time: getnstimeofday(&ts_postidle); ts_idle = timespec_sub(ts_postidle, ts_preidle); local_irq_enable(); local_fiq_enable(); return ts_idle.tv_nsec / NSEC_PER_USEC + ts_idle.tv_sec * USEC_PER_SEC; }
static void delayacct_end(struct timespec *start, struct timespec *end, u64 *total, u32 *count) { struct timespec ts; s64 ns; unsigned long flags; do_posix_clock_monotonic_gettime(end); ts = timespec_sub(*end, *start); ns = timespec_to_ns(&ts); if (ns < 0) return; spin_lock_irqsave(¤t->delays->lock, flags); *total += ns; (*count)++; spin_unlock_irqrestore(¤t->delays->lock, flags); }
/** * _omap_device_deactivate - decrease device readiness * @od: struct omap_device * * @ignore_lat: decrease to latency target (0) or full inactivity (1)? * * Decrease readiness of omap_device @od (thus increasing device * wakeup latency, but conserving power). If @ignore_lat is * IGNORE_WAKEUP_LAT, make the omap_device fully inactive. Otherwise, * if @ignore_lat is USE_WAKEUP_LAT, and the device's maximum wakeup * latency is less than the requested maximum wakeup latency, step * forwards in the omap_device_pm_latency table to ensure the device's * maximum wakeup latency is less than or equal to the requested * maximum wakeup latency. Returns 0. */ static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat) { struct timespec a, b, c; pr_debug("omap_device: %s: deactivating\n", od->pdev.name); while (od->pm_lat_level < od->pm_lats_cnt) { struct omap_device_pm_latency *odpl; unsigned long long deact_lat = 0; odpl = od->pm_lats + od->pm_lat_level; if (!ignore_lat && ((od->dev_wakeup_lat + odpl->activate_lat) > od->_dev_wakeup_lat_limit)) break; getnstimeofday(&a); /* XXX check return code */ odpl->deactivate_func(od); getnstimeofday(&b); c = timespec_sub(b, a); deact_lat = timespec_to_ns(&c) * NSEC_PER_USEC; pr_debug("omap_device: %s: pm_lat %d: deactivate: elapsed time " "%llu usec\n", od->pdev.name, od->pm_lat_level, deact_lat); WARN(deact_lat > odpl->deactivate_lat, "omap_device: %s.%d: " "deactivate step %d took longer than expected " "(%llu > %d)\n", od->pdev.name, od->pdev.id, od->pm_lat_level, deact_lat, odpl->deactivate_lat); od->dev_wakeup_lat += odpl->activate_lat; od->pm_lat_level++; } return 0; }
static long estimate_accuracy(struct timespec *tv) { unsigned long ret; struct timespec now; /* * Realtime tasks get a slack of 0 for obvious reasons. */ if (rt_task(current)) return 0; ktime_get_ts(&now); now = timespec_sub(*tv, now); ret = __estimate_accuracy(&now); if (ret < current->timer_slack_ns) return current->timer_slack_ns; return ret; }
static void rtc_sync_save_delta(void) { struct rtc_time rtc_time; static time_t rtc_time_t; struct timespec ts_system, ts_rtc; getnstimeofday(&ts_system); s3c_rtc_gettime(NULL, &rtc_time); rtc_tm_to_time(&rtc_time, &rtc_time_t); /* RTC precision is 1 second; adjust delta for avg 1/2 sec err */ set_normalized_timespec(&ts_rtc, rtc_time_t, NSEC_PER_SEC>>1); ts_saved_delta = timespec_sub(ts_system, ts_rtc); #ifdef CONFIG_RTC_S3C_SYNC_SYSTEM_TIME_DEBUG printk ("RTC_SYNC: save delta sec:%d nsec:%d\n", ts_saved_delta.tv_sec, ts_saved_delta.tv_nsec); #endif }
void clockobj_set_date(struct clockobj *clkobj, ticks_t ticks) { struct timespec now; /* * XXX: we grab the lock to exclude other threads from reading * the clock offset while we update it, so that they either * compute against the old value, or the new one, but always * see a valid offset. */ read_lock_nocancel(&clkobj->lock); __RT(clock_gettime(CLOCK_COPPERPLATE, &now)); __clockobj_ticks_to_timespec(clkobj, ticks, &clkobj->epoch); timespec_sub(&clkobj->offset, &clkobj->epoch, &now); read_unlock(&clkobj->lock); }
void tl_select_relay(struct tr_info_list *list){ struct timespec tl_diff; getrawmonotonic(&tl_end); tl_diff = timespec_sub(tl_end, tl_start); //printk("Topology learning time: %ld\n", timespec_to_ns(&tl_diff)); if(list == NULL){ printk("Select Relay error1\n"); return; } if(list->next == NULL){ printk("Select Relay error2\n"); return; } tr_info_list_arrangement(list); if(MNPRELAY) mnp_relay(list); else min_max_relay(list); }
/** * omap3_enter_idle - Programs OMAP3 to enter the specified state * @dev: cpuidle device * @state: The target state to be programmed * * Called from the CPUidle framework to program the device to the * specified target state selected by the governor. */ static int omap3_enter_idle(struct cpuidle_device *dev, struct cpuidle_state *state) { struct omap3_idle_statedata *cx = cpuidle_get_statedata(state); struct timespec ts_preidle, ts_postidle, ts_idle; u32 mpu_state = cx->mpu_state, core_state = cx->core_state; /* Used to keep track of the total time in idle */ getnstimeofday(&ts_preidle); local_irq_disable(); local_fiq_disable(); pwrdm_set_next_pwrst(mpu_pd, mpu_state); pwrdm_set_next_pwrst(core_pd, core_state); if (omap_irq_pending() || need_resched()) goto return_sleep_time; /* Deny idle for C1 */ if (state == &dev->states[0]) { pwrdm_for_each_clkdm(mpu_pd, _cpuidle_deny_idle); pwrdm_for_each_clkdm(core_pd, _cpuidle_deny_idle); } /* Execute ARM wfi */ omap_sram_idle(false); /* Re-allow idle for C1 */ if (state == &dev->states[0]) { pwrdm_for_each_clkdm(mpu_pd, _cpuidle_allow_idle); pwrdm_for_each_clkdm(core_pd, _cpuidle_allow_idle); } return_sleep_time: getnstimeofday(&ts_postidle); ts_idle = timespec_sub(ts_postidle, ts_preidle); local_irq_enable(); local_fiq_enable(); return ts_idle.tv_nsec / NSEC_PER_USEC + ts_idle.tv_sec * USEC_PER_SEC; }
/* * Monitor an averaged frame interval. If the average deviates too much * from the nominal frame rate, send the frame interval error event. The * frame intervals are averaged in order to quiet noise from * (presumably random) interrupt latency. */ static void frame_interval_monitor(struct imx_media_fim *fim, struct timespec *ts) { unsigned long interval, error, error_avg; bool send_event = false; struct timespec diff; if (!fim->enabled || ++fim->counter <= 0) goto out_update_ts; diff = timespec_sub(*ts, fim->last_ts); interval = diff.tv_sec * 1000 * 1000 + diff.tv_nsec / 1000; error = abs(interval - fim->nominal); if (fim->tolerance_max && error >= fim->tolerance_max) { dev_dbg(fim->sd->dev, "FIM: %lu ignored, out of tolerance bounds\n", error); fim->counter--; goto out_update_ts; } fim->sum += error; if (fim->counter == fim->num_avg) { error_avg = DIV_ROUND_CLOSEST(fim->sum, fim->num_avg); if (error_avg > fim->tolerance_min) send_event = true; dev_dbg(fim->sd->dev, "FIM: error: %lu usec%s\n", error_avg, send_event ? " (!!!)" : ""); fim->counter = 0; fim->sum = 0; } out_update_ts: fim->last_ts = *ts; if (send_event) send_fim_event(fim, error_avg); }