~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to kernel/timer.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#include <linux/irq_work.h>
41
41
#include <linux/sched.h>
42
42
#include <linux/slab.h>
43
 
#include <trace/timer.h>
44
43
 
45
 
#include <asm/byteorder.h>
46
44
#include <asm/uaccess.h>
47
45
#include <asm/unistd.h>
48
46
#include <asm/div64.h>
49
47
#include <asm/timex.h>
50
48
#include <asm/io.h>
51
 
#include <asm/irq_regs.h>
52
49
 
53
50
#define CREATE_TRACE_POINTS
54
51
#include <trace/events/timer.h>
57
54
 
58
55
EXPORT_SYMBOL(jiffies_64);
59
56
 
60
 
DEFINE_TRACE(timer_set);
61
 
DEFINE_TRACE(timer_update_time);
62
 
DEFINE_TRACE(timer_timeout);
63
 
 
64
 
#ifdef CONFIG_X86
65
 
#if defined(__LITTLE_ENDIAN) || (BITS_PER_LONG >= 64)
66
 
asm(".global jiffies; jiffies = jiffies_64");
67
 
#else
68
 
asm(".global jiffies; jiffies = jiffies_64 + 4");
69
 
#endif
70
 
#endif
71
 
 
72
57
/*
73
58
 * per-CPU timer vector definitions:
74
59
 */
381
366
                i = (expires >> (TVR_BITS + 3 * TVN_BITS)) & TVN_MASK;
382
367
                vec = base->tv5.vec + i;
383
368
        }
384
 
        trace_timer_set(timer);
385
369
        /*
386
370
         * Timers are FIFO:
387
371
         */
420
404
 
421
405
static struct debug_obj_descr timer_debug_descr;
422
406
 
 
407
static void *timer_debug_hint(void *addr)
 
408
{
 
409
        return ((struct timer_list *) addr)->function;
 
410
}
 
411
 
423
412
/*
424
413
 * fixup_init is called when:
425
414
 * - an active object is initialized
493
482
 
494
483
static struct debug_obj_descr timer_debug_descr = {
495
484
        .name           = "timer_list",
 
485
        .debug_hint     = timer_debug_hint,
496
486
        .fixup_init     = timer_fixup_init,
497
487
        .fixup_activate = timer_fixup_activate,
498
488
        .fixup_free     = timer_fixup_free,
759
749
        unsigned long expires_limit, mask;
760
750
        int bit;
761
751
 
762
 
        expires_limit = expires;
763
 
 
764
752
        if (timer->slack >= 0) {
765
753
                expires_limit = expires + timer->slack;
766
754
        } else {
767
 
                unsigned long now = jiffies;
768
 
 
769
 
                /* No slack, if already expired else auto slack 0.4% */
770
 
                if (time_after(expires, now))
771
 
                        expires_limit = expires + (expires - now)/256;
 
755
                long delta = expires - jiffies;
 
756
 
 
757
                if (delta < 256)
 
758
                        return expires;
 
759
 
 
760
                expires_limit = expires + delta / 256;
772
761
        }
773
762
        mask = expires ^ expires_limit;
774
763
        if (mask == 0)
805
794
 */
806
795
int mod_timer(struct timer_list *timer, unsigned long expires)
807
796
{
 
797
        expires = apply_slack(timer, expires);
 
798
 
808
799
        /*
809
800
         * This is a common optimization triggered by the
810
801
         * networking code - if the timer is re-modified
813
804
        if (timer_pending(timer) && timer->expires == expires)
814
805
                return 1;
815
806
 
816
 
        expires = apply_slack(timer, expires);
817
 
 
818
807
        return __mod_timer(timer, expires, false, TIMER_NOT_PINNED);
819
808
}
820
809
EXPORT_SYMBOL(mod_timer);
980
969
 * add_timer_on(). Upon exit the timer is not queued and the handler is
981
970
 * not running on any CPU.
982
971
 *
 
972
 * Note: You must not hold locks that are held in interrupt context
 
973
 *   while calling this function. Even if the lock has nothing to do
 
974
 *   with the timer in question.  Here's why:
 
975
 *
 
976
 *    CPU0                             CPU1
 
977
 *    ----                             ----
 
978
 *                                   <SOFTIRQ>
 
979
 *                                   call_timer_fn();
 
980
 *                                     base->running_timer = mytimer;
 
981
 *  spin_lock_irq(somelock);
 
982
 *                                     <IRQ>
 
983
 *                                        spin_lock(somelock);
 
984
 *  del_timer_sync(mytimer);
 
985
 *   while (base->running_timer == mytimer);
 
986
 *
 
987
 * Now del_timer_sync() will never return and never release somelock.
 
988
 * The interrupt on the other CPU is waiting to grab somelock but
 
989
 * it has interrupted the softirq that CPU0 is waiting to finish.
 
990
 *
983
991
 * The function returns whether it has deactivated a pending timer or not.
984
992
 */
985
993
int del_timer_sync(struct timer_list *timer)
987
995
#ifdef CONFIG_LOCKDEP
988
996
        unsigned long flags;
989
997
 
 
998
        /*
 
999
         * If lockdep gives a backtrace here, please reference
 
1000
         * the synchronization rules above.
 
1001
         */
990
1002
        local_irq_save(flags);
991
1003
        lock_map_acquire(&timer->lockdep_map);
992
1004
        lock_map_release(&timer->lockdep_map);
1311
1323
        raise_softirq(TIMER_SOFTIRQ);
1312
1324
}
1313
1325
 
1314
 
/*
1315
 
 * The 64-bit jiffies value is not atomic - you MUST NOT read it
1316
 
 * without sampling the sequence number in xtime_lock.
1317
 
 * jiffies is defined in the linker script...
1318
 
 */
1319
 
 
1320
 
void do_timer(unsigned long ticks)
1321
 
{
1322
 
        struct timespec curtime, wtom;
1323
 
 
1324
 
        jiffies_64 += ticks;
1325
 
        update_wall_time();
1326
 
        curtime = __current_kernel_time();
1327
 
        wtom = __get_wall_to_monotonic();
1328
 
        trace_timer_update_time(&curtime, &wtom);
1329
 
        calc_global_load(ticks);
1330
 
}
1331
 
 
1332
1326
#ifdef __ARCH_WANT_SYS_ALARM
1333
1327
 
1334
1328
/*
1408
1402
 
1409
1403
static void process_timeout(unsigned long __data)
1410
1404
{
1411
 
        struct task_struct *task = (struct task_struct *)__data;
1412
 
        trace_timer_timeout(task);
1413
 
        wake_up_process(task);
 
1405
        wake_up_process((struct task_struct *)__data);
1414
1406
}
1415
1407
 
1416
1408
/**