~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to kernel/posix-cpu-timers.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno
  • Date: 2011-06-07 12:14:05 UTC
  • mfrom: (43.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110607121405-i3h1rd7nrnd2b73h
Tags: 2.6.39-2
[ Ben Hutchings ]
* [x86] Enable BACKLIGHT_APPLE, replacing BACKLIGHT_MBP_NVIDIA
  (Closes: #627492)
* cgroups: Disable memory resource controller by default. Allow it
  to be enabled using kernel parameter 'cgroup_enable=memory'.
* rt2800usb: Enable support for more USB devices including
  Linksys WUSB600N (Closes: #596626) (this change was accidentally
  omitted from 2.6.39-1)
* [x86] Remove Celeron from list of processors supporting PAE. Most
  'Celeron M' models do not.
* Update debconf template translations:
  - Swedish (Martin Bagge) (Closes: #628932)
  - French (David Prévot) (Closes: #628191)
* aufs: Update for 2.6.39 (Closes: #627837)
* Add stable 2.6.39.1, including:
  - ext4: dont set PageUptodate in ext4_end_bio()
  - pata_cmd64x: fix boot crash on parisc (Closes: #622997, #622745)
  - ext3: Fix fs corruption when make_indexed_dir() fails
  - netfilter: nf_ct_sip: validate Content-Length in TCP SIP messages
  - sctp: fix race between sctp_bind_addr_free() and
    sctp_bind_addr_conflict()
  - sctp: fix memory leak of the ASCONF queue when free asoc
  - md/bitmap: fix saving of events_cleared and other state
  - cdc_acm: Fix oops when Droids MuIn LCD is connected
  - cx88: Fix conversion from BKL to fine-grained locks (Closes: #619827)
  - keys: Set cred->user_ns in key_replace_session_keyring (CVE-2011-2184)
  - tmpfs: fix race between truncate and writepage
  - nfs41: Correct offset for LAYOUTCOMMIT
  - xen/mmu: fix a race window causing leave_mm BUG()
  - ext4: fix possible use-after-free in ext4_remove_li_request()
  For the complete list of changes, see:
   http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.39.1
* Bump ABI to 2
* netfilter: Enable IP_SET, IP_SET_BITMAP_IP, IP_SET_BITMAP_IPMAC,
  IP_SET_BITMAP_PORT, IP_SET_HASH_IP, IP_SET_HASH_IPPORT,
  IP_SET_HASH_IPPORTIP, IP_SET_HASH_IPPORTNET, IP_SET_HASH_NET,
  IP_SET_HASH_NETPORT, IP_SET_LIST_SET, NETFILTER_XT_SET as modules
  (Closes: #629401)

[ Aurelien Jarno ]
* [mipsel/loongson-2f] Disable_SCSI_LPFC to workaround GCC ICE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
176
176
        return p->utime;
177
177
}
178
178
 
179
 
int posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
 
179
static int
 
180
posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
180
181
{
181
182
        int error = check_clock(which_clock);
182
183
        if (!error) {
194
195
        return error;
195
196
}
196
197
 
197
 
int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)
 
198
static int
 
199
posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)
198
200
{
199
201
        /*
200
202
         * You can never reset a CPU clock, but we check for other errors
317
319
}
318
320
 
319
321
 
320
 
int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
 
322
static int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
321
323
{
322
324
        const pid_t pid = CPUCLOCK_PID(which_clock);
323
325
        int error = -EINVAL;
379
381
 * This is called from sys_timer_create() and do_cpu_nanosleep() with the
380
382
 * new timer already all-zeros initialized.
381
383
 */
382
 
int posix_cpu_timer_create(struct k_itimer *new_timer)
 
384
static int posix_cpu_timer_create(struct k_itimer *new_timer)
383
385
{
384
386
        int ret = 0;
385
387
        const pid_t pid = CPUCLOCK_PID(new_timer->it_clock);
425
427
 * If we return TIMER_RETRY, it's necessary to release the timer's lock
426
428
 * and try again.  (This happens when the timer is in the middle of firing.)
427
429
 */
428
 
int posix_cpu_timer_del(struct k_itimer *timer)
 
430
static int posix_cpu_timer_del(struct k_itimer *timer)
429
431
{
430
432
        struct task_struct *p = timer->it.cpu.task;
431
433
        int ret = 0;
665
667
 * If we return TIMER_RETRY, it's necessary to release the timer's lock
666
668
 * and try again.  (This happens when the timer is in the middle of firing.)
667
669
 */
668
 
int posix_cpu_timer_set(struct k_itimer *timer, int flags,
669
 
                        struct itimerspec *new, struct itimerspec *old)
 
670
static int posix_cpu_timer_set(struct k_itimer *timer, int flags,
 
671
                               struct itimerspec *new, struct itimerspec *old)
670
672
{
671
673
        struct task_struct *p = timer->it.cpu.task;
672
674
        union cpu_time_count old_expires, new_expires, old_incr, val;
820
822
        return ret;
821
823
}
822
824
 
823
 
void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp)
 
825
static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp)
824
826
{
825
827
        union cpu_time_count now;
826
828
        struct task_struct *p = timer->it.cpu.task;
1345
1347
 
1346
1348
        /*
1347
1349
         * Now that all the timers on our list have the firing flag,
1348
 
         * noone will touch their list entries but us.  We'll take
 
1350
         * no one will touch their list entries but us.  We'll take
1349
1351
         * each timer's lock before clearing its firing flag, so no
1350
1352
         * timer call will interfere.
1351
1353
         */
1481
1483
        return error;
1482
1484
}
1483
1485
 
1484
 
int posix_cpu_nsleep(const clockid_t which_clock, int flags,
1485
 
                     struct timespec *rqtp, struct timespec __user *rmtp)
 
1486
static long posix_cpu_nsleep_restart(struct restart_block *restart_block);
 
1487
 
 
1488
static int posix_cpu_nsleep(const clockid_t which_clock, int flags,
 
1489
                            struct timespec *rqtp, struct timespec __user *rmtp)
1486
1490
{
1487
1491
        struct restart_block *restart_block =
1488
 
            &current_thread_info()->restart_block;
 
1492
                &current_thread_info()->restart_block;
1489
1493
        struct itimerspec it;
1490
1494
        int error;
1491
1495
 
1501
1505
 
1502
1506
        if (error == -ERESTART_RESTARTBLOCK) {
1503
1507
 
1504
 
                if (flags & TIMER_ABSTIME)
 
1508
                if (flags & TIMER_ABSTIME)
1505
1509
                        return -ERESTARTNOHAND;
1506
1510
                /*
1507
 
                 * Report back to the user the time still remaining.
1508
 
                 */
1509
 
                if (rmtp != NULL && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
 
1511
                 * Report back to the user the time still remaining.
 
1512
                 */
 
1513
                if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
1510
1514
                        return -EFAULT;
1511
1515
 
1512
1516
                restart_block->fn = posix_cpu_nsleep_restart;
1513
 
                restart_block->arg0 = which_clock;
1514
 
                restart_block->arg1 = (unsigned long) rmtp;
1515
 
                restart_block->arg2 = rqtp->tv_sec;
1516
 
                restart_block->arg3 = rqtp->tv_nsec;
 
1517
                restart_block->nanosleep.index = which_clock;
 
1518
                restart_block->nanosleep.rmtp = rmtp;
 
1519
                restart_block->nanosleep.expires = timespec_to_ns(rqtp);
1517
1520
        }
1518
1521
        return error;
1519
1522
}
1520
1523
 
1521
 
long posix_cpu_nsleep_restart(struct restart_block *restart_block)
 
1524
static long posix_cpu_nsleep_restart(struct restart_block *restart_block)
1522
1525
{
1523
 
        clockid_t which_clock = restart_block->arg0;
1524
 
        struct timespec __user *rmtp;
 
1526
        clockid_t which_clock = restart_block->nanosleep.index;
1525
1527
        struct timespec t;
1526
1528
        struct itimerspec it;
1527
1529
        int error;
1528
1530
 
1529
 
        rmtp = (struct timespec __user *) restart_block->arg1;
1530
 
        t.tv_sec = restart_block->arg2;
1531
 
        t.tv_nsec = restart_block->arg3;
 
1531
        t = ns_to_timespec(restart_block->nanosleep.expires);
1532
1532
 
1533
 
        restart_block->fn = do_no_restart_syscall;
1534
1533
        error = do_cpu_nanosleep(which_clock, TIMER_ABSTIME, &t, &it);
1535
1534
 
1536
1535
        if (error == -ERESTART_RESTARTBLOCK) {
 
1536
                struct timespec __user *rmtp = restart_block->nanosleep.rmtp;
1537
1537
                /*
1538
 
                 * Report back to the user the time still remaining.
1539
 
                 */
1540
 
                if (rmtp != NULL && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
 
1538
                 * Report back to the user the time still remaining.
 
1539
                 */
 
1540
                if (rmtp && copy_to_user(rmtp, &it.it_value, sizeof *rmtp))
1541
1541
                        return -EFAULT;
1542
1542
 
1543
 
                restart_block->fn = posix_cpu_nsleep_restart;
1544
 
                restart_block->arg0 = which_clock;
1545
 
                restart_block->arg1 = (unsigned long) rmtp;
1546
 
                restart_block->arg2 = t.tv_sec;
1547
 
                restart_block->arg3 = t.tv_nsec;
 
1543
                restart_block->nanosleep.expires = timespec_to_ns(&t);
1548
1544
        }
1549
1545
        return error;
1550
1546
 
1551
1547
}
1552
1548
 
1553
 
 
1554
1549
#define PROCESS_CLOCK   MAKE_PROCESS_CPUCLOCK(0, CPUCLOCK_SCHED)
1555
1550
#define THREAD_CLOCK    MAKE_THREAD_CPUCLOCK(0, CPUCLOCK_SCHED)
1556
1551
 
1594
1589
        timer->it_clock = THREAD_CLOCK;
1595
1590
        return posix_cpu_timer_create(timer);
1596
1591
}
1597
 
static int thread_cpu_nsleep(const clockid_t which_clock, int flags,
1598
 
                              struct timespec *rqtp, struct timespec __user *rmtp)
1599
 
{
1600
 
        return -EINVAL;
1601
 
}
1602
 
static long thread_cpu_nsleep_restart(struct restart_block *restart_block)
1603
 
{
1604
 
        return -EINVAL;
1605
 
}
 
1592
 
 
1593
struct k_clock clock_posix_cpu = {
 
1594
        .clock_getres   = posix_cpu_clock_getres,
 
1595
        .clock_set      = posix_cpu_clock_set,
 
1596
        .clock_get      = posix_cpu_clock_get,
 
1597
        .timer_create   = posix_cpu_timer_create,
 
1598
        .nsleep         = posix_cpu_nsleep,
 
1599
        .nsleep_restart = posix_cpu_nsleep_restart,
 
1600
        .timer_set      = posix_cpu_timer_set,
 
1601
        .timer_del      = posix_cpu_timer_del,
 
1602
        .timer_get      = posix_cpu_timer_get,
 
1603
};
1606
1604
 
1607
1605
static __init int init_posix_cpu_timers(void)
1608
1606
{
1609
1607
        struct k_clock process = {
1610
 
                .clock_getres = process_cpu_clock_getres,
1611
 
                .clock_get = process_cpu_clock_get,
1612
 
                .clock_set = do_posix_clock_nosettime,
1613
 
                .timer_create = process_cpu_timer_create,
1614
 
                .nsleep = process_cpu_nsleep,
1615
 
                .nsleep_restart = process_cpu_nsleep_restart,
 
1608
                .clock_getres   = process_cpu_clock_getres,
 
1609
                .clock_get      = process_cpu_clock_get,
 
1610
                .timer_create   = process_cpu_timer_create,
 
1611
                .nsleep         = process_cpu_nsleep,
 
1612
                .nsleep_restart = process_cpu_nsleep_restart,
1616
1613
        };
1617
1614
        struct k_clock thread = {
1618
 
                .clock_getres = thread_cpu_clock_getres,
1619
 
                .clock_get = thread_cpu_clock_get,
1620
 
                .clock_set = do_posix_clock_nosettime,
1621
 
                .timer_create = thread_cpu_timer_create,
1622
 
                .nsleep = thread_cpu_nsleep,
1623
 
                .nsleep_restart = thread_cpu_nsleep_restart,
 
1615
                .clock_getres   = thread_cpu_clock_getres,
 
1616
                .clock_get      = thread_cpu_clock_get,
 
1617
                .timer_create   = thread_cpu_timer_create,
1624
1618
        };
1625
1619
        struct timespec ts;
1626
1620
 
1627
 
        register_posix_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
1628
 
        register_posix_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
 
1621
        posix_timers_register_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
 
1622
        posix_timers_register_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
1629
1623
 
1630
1624
        cputime_to_timespec(cputime_one_jiffy, &ts);
1631
1625
        onecputick = ts.tv_nsec;