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

« back to all changes in this revision

Viewing changes to kernel/cpuset.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:
1015
1015
        struct cpuset *cs;
1016
1016
        int migrate;
1017
1017
        const nodemask_t *oldmem = scan->data;
1018
 
        NODEMASK_ALLOC(nodemask_t, newmems, GFP_KERNEL);
1019
 
 
1020
 
        if (!newmems)
1021
 
                return;
 
1018
        static nodemask_t newmems;      /* protected by cgroup_mutex */
1022
1019
 
1023
1020
        cs = cgroup_cs(scan->cg);
1024
 
        guarantee_online_mems(cs, newmems);
1025
 
 
1026
 
        cpuset_change_task_nodemask(p, newmems);
1027
 
 
1028
 
        NODEMASK_FREE(newmems);
 
1021
        guarantee_online_mems(cs, &newmems);
 
1022
 
 
1023
        cpuset_change_task_nodemask(p, &newmems);
1029
1024
 
1030
1025
        mm = get_task_mm(p);
1031
1026
        if (!mm)
1164
1159
static int update_relax_domain_level(struct cpuset *cs, s64 val)
1165
1160
{
1166
1161
#ifdef CONFIG_SMP
1167
 
        if (val < -1 || val >= SD_LV_MAX)
 
1162
        if (val < -1 || val >= sched_domain_level_max)
1168
1163
                return -EINVAL;
1169
1164
#endif
1170
1165
 
1372
1367
        return val;
1373
1368
}
1374
1369
 
1375
 
/* Protected by cgroup_lock */
1376
 
static cpumask_var_t cpus_attach;
1377
 
 
1378
1370
/* Called by cgroups to determine if a cpuset is usable; cgroup_mutex held */
1379
1371
static int cpuset_can_attach(struct cgroup_subsys *ss, struct cgroup *cont,
1380
 
                             struct task_struct *tsk, bool threadgroup)
 
1372
                             struct task_struct *tsk)
1381
1373
{
1382
 
        int ret;
1383
1374
        struct cpuset *cs = cgroup_cs(cont);
1384
1375
 
1385
1376
        if (cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed))
1396
1387
        if (tsk->flags & PF_THREAD_BOUND)
1397
1388
                return -EINVAL;
1398
1389
 
1399
 
        ret = security_task_setscheduler(tsk);
1400
 
        if (ret)
1401
 
                return ret;
1402
 
        if (threadgroup) {
1403
 
                struct task_struct *c;
1404
 
 
1405
 
                rcu_read_lock();
1406
 
                list_for_each_entry_rcu(c, &tsk->thread_group, thread_group) {
1407
 
                        ret = security_task_setscheduler(c);
1408
 
                        if (ret) {
1409
 
                                rcu_read_unlock();
1410
 
                                return ret;
1411
 
                        }
1412
 
                }
1413
 
                rcu_read_unlock();
1414
 
        }
1415
1390
        return 0;
1416
1391
}
1417
1392
 
1418
 
static void cpuset_attach_task(struct task_struct *tsk, nodemask_t *to,
1419
 
                               struct cpuset *cs)
 
1393
static int cpuset_can_attach_task(struct cgroup *cgrp, struct task_struct *task)
 
1394
{
 
1395
        return security_task_setscheduler(task);
 
1396
}
 
1397
 
 
1398
/*
 
1399
 * Protected by cgroup_lock. The nodemasks must be stored globally because
 
1400
 * dynamically allocating them is not allowed in pre_attach, and they must
 
1401
 * persist among pre_attach, attach_task, and attach.
 
1402
 */
 
1403
static cpumask_var_t cpus_attach;
 
1404
static nodemask_t cpuset_attach_nodemask_from;
 
1405
static nodemask_t cpuset_attach_nodemask_to;
 
1406
 
 
1407
/* Set-up work for before attaching each task. */
 
1408
static void cpuset_pre_attach(struct cgroup *cont)
 
1409
{
 
1410
        struct cpuset *cs = cgroup_cs(cont);
 
1411
 
 
1412
        if (cs == &top_cpuset)
 
1413
                cpumask_copy(cpus_attach, cpu_possible_mask);
 
1414
        else
 
1415
                guarantee_online_cpus(cs, cpus_attach);
 
1416
 
 
1417
        guarantee_online_mems(cs, &cpuset_attach_nodemask_to);
 
1418
}
 
1419
 
 
1420
/* Per-thread attachment work. */
 
1421
static void cpuset_attach_task(struct cgroup *cont, struct task_struct *tsk)
1420
1422
{
1421
1423
        int err;
 
1424
        struct cpuset *cs = cgroup_cs(cont);
 
1425
 
1422
1426
        /*
1423
1427
         * can_attach beforehand should guarantee that this doesn't fail.
1424
1428
         * TODO: have a better way to handle failure here
1426
1430
        err = set_cpus_allowed_ptr(tsk, cpus_attach);
1427
1431
        WARN_ON_ONCE(err);
1428
1432
 
1429
 
        cpuset_change_task_nodemask(tsk, to);
 
1433
        cpuset_change_task_nodemask(tsk, &cpuset_attach_nodemask_to);
1430
1434
        cpuset_update_task_spread_flag(cs, tsk);
1431
 
 
1432
1435
}
1433
1436
 
1434
1437
static void cpuset_attach(struct cgroup_subsys *ss, struct cgroup *cont,
1435
 
                          struct cgroup *oldcont, struct task_struct *tsk,
1436
 
                          bool threadgroup)
 
1438
                          struct cgroup *oldcont, struct task_struct *tsk)
1437
1439
{
1438
1440
        struct mm_struct *mm;
1439
1441
        struct cpuset *cs = cgroup_cs(cont);
1440
1442
        struct cpuset *oldcs = cgroup_cs(oldcont);
1441
 
        NODEMASK_ALLOC(nodemask_t, from, GFP_KERNEL);
1442
 
        NODEMASK_ALLOC(nodemask_t, to, GFP_KERNEL);
1443
 
 
1444
 
        if (from == NULL || to == NULL)
1445
 
                goto alloc_fail;
1446
 
 
1447
 
        if (cs == &top_cpuset) {
1448
 
                cpumask_copy(cpus_attach, cpu_possible_mask);
1449
 
        } else {
1450
 
                guarantee_online_cpus(cs, cpus_attach);
1451
 
        }
1452
 
        guarantee_online_mems(cs, to);
1453
 
 
1454
 
        /* do per-task migration stuff possibly for each in the threadgroup */
1455
 
        cpuset_attach_task(tsk, to, cs);
1456
 
        if (threadgroup) {
1457
 
                struct task_struct *c;
1458
 
                rcu_read_lock();
1459
 
                list_for_each_entry_rcu(c, &tsk->thread_group, thread_group) {
1460
 
                        cpuset_attach_task(c, to, cs);
1461
 
                }
1462
 
                rcu_read_unlock();
1463
 
        }
1464
 
 
1465
 
        /* change mm; only needs to be done once even if threadgroup */
1466
 
        *from = oldcs->mems_allowed;
1467
 
        *to = cs->mems_allowed;
 
1443
 
 
1444
        /*
 
1445
         * Change mm, possibly for multiple threads in a threadgroup. This is
 
1446
         * expensive and may sleep.
 
1447
         */
 
1448
        cpuset_attach_nodemask_from = oldcs->mems_allowed;
 
1449
        cpuset_attach_nodemask_to = cs->mems_allowed;
1468
1450
        mm = get_task_mm(tsk);
1469
1451
        if (mm) {
1470
 
                mpol_rebind_mm(mm, to);
 
1452
                mpol_rebind_mm(mm, &cpuset_attach_nodemask_to);
1471
1453
                if (is_memory_migrate(cs))
1472
 
                        cpuset_migrate_mm(mm, from, to);
 
1454
                        cpuset_migrate_mm(mm, &cpuset_attach_nodemask_from,
 
1455
                                          &cpuset_attach_nodemask_to);
1473
1456
                mmput(mm);
1474
1457
        }
1475
 
 
1476
 
alloc_fail:
1477
 
        NODEMASK_FREE(from);
1478
 
        NODEMASK_FREE(to);
1479
1458
}
1480
1459
 
1481
1460
/* The various types of files and directories in a cpuset file system */
1610
1589
 * across a page fault.
1611
1590
 */
1612
1591
 
1613
 
static int cpuset_sprintf_cpulist(char *page, struct cpuset *cs)
 
1592
static size_t cpuset_sprintf_cpulist(char *page, struct cpuset *cs)
1614
1593
{
1615
 
        int ret;
 
1594
        size_t count;
1616
1595
 
1617
1596
        mutex_lock(&callback_mutex);
1618
 
        ret = cpulist_scnprintf(page, PAGE_SIZE, cs->cpus_allowed);
 
1597
        count = cpulist_scnprintf(page, PAGE_SIZE, cs->cpus_allowed);
1619
1598
        mutex_unlock(&callback_mutex);
1620
1599
 
1621
 
        return ret;
 
1600
        return count;
1622
1601
}
1623
1602
 
1624
 
static int cpuset_sprintf_memlist(char *page, struct cpuset *cs)
 
1603
static size_t cpuset_sprintf_memlist(char *page, struct cpuset *cs)
1625
1604
{
1626
 
        NODEMASK_ALLOC(nodemask_t, mask, GFP_KERNEL);
1627
 
        int retval;
1628
 
 
1629
 
        if (mask == NULL)
1630
 
                return -ENOMEM;
 
1605
        size_t count;
1631
1606
 
1632
1607
        mutex_lock(&callback_mutex);
1633
 
        *mask = cs->mems_allowed;
 
1608
        count = nodelist_scnprintf(page, PAGE_SIZE, cs->mems_allowed);
1634
1609
        mutex_unlock(&callback_mutex);
1635
1610
 
1636
 
        retval = nodelist_scnprintf(page, PAGE_SIZE, *mask);
1637
 
 
1638
 
        NODEMASK_FREE(mask);
1639
 
 
1640
 
        return retval;
 
1611
        return count;
1641
1612
}
1642
1613
 
1643
1614
static ssize_t cpuset_common_file_read(struct cgroup *cont,
1831
1802
}
1832
1803
 
1833
1804
/*
1834
 
 * post_clone() is called at the end of cgroup_clone().
1835
 
 * 'cgroup' was just created automatically as a result of
1836
 
 * a cgroup_clone(), and the current task is about to
1837
 
 * be moved into 'cgroup'.
 
1805
 * post_clone() is called during cgroup_create() when the
 
1806
 * clone_children mount argument was specified.  The cgroup
 
1807
 * can not yet have any tasks.
1838
1808
 *
1839
1809
 * Currently we refuse to set up the cgroup - thereby
1840
1810
 * refusing the task to be entered, and as a result refusing
1862
1832
        cs = cgroup_cs(cgroup);
1863
1833
        parent_cs = cgroup_cs(parent);
1864
1834
 
 
1835
        mutex_lock(&callback_mutex);
1865
1836
        cs->mems_allowed = parent_cs->mems_allowed;
1866
1837
        cpumask_copy(cs->cpus_allowed, parent_cs->cpus_allowed);
 
1838
        mutex_unlock(&callback_mutex);
1867
1839
        return;
1868
1840
}
1869
1841
 
1931
1903
        .create = cpuset_create,
1932
1904
        .destroy = cpuset_destroy,
1933
1905
        .can_attach = cpuset_can_attach,
 
1906
        .can_attach_task = cpuset_can_attach_task,
 
1907
        .pre_attach = cpuset_pre_attach,
 
1908
        .attach_task = cpuset_attach_task,
1934
1909
        .attach = cpuset_attach,
1935
1910
        .populate = cpuset_populate,
1936
1911
        .post_clone = cpuset_post_clone,
2066
2041
        struct cpuset *cp;      /* scans cpusets being updated */
2067
2042
        struct cpuset *child;   /* scans child cpusets of cp */
2068
2043
        struct cgroup *cont;
2069
 
        NODEMASK_ALLOC(nodemask_t, oldmems, GFP_KERNEL);
2070
 
 
2071
 
        if (oldmems == NULL)
2072
 
                return;
 
2044
        static nodemask_t oldmems;      /* protected by cgroup_mutex */
2073
2045
 
2074
2046
        list_add_tail((struct list_head *)&root->stack_list, &queue);
2075
2047
 
2086
2058
                    nodes_subset(cp->mems_allowed, node_states[N_HIGH_MEMORY]))
2087
2059
                        continue;
2088
2060
 
2089
 
                *oldmems = cp->mems_allowed;
 
2061
                oldmems = cp->mems_allowed;
2090
2062
 
2091
2063
                /* Remove offline cpus and mems from this cpuset. */
2092
2064
                mutex_lock(&callback_mutex);
2102
2074
                        remove_tasks_in_empty_cpuset(cp);
2103
2075
                else {
2104
2076
                        update_tasks_cpumask(cp, NULL);
2105
 
                        update_tasks_nodemask(cp, oldmems, NULL);
 
2077
                        update_tasks_nodemask(cp, &oldmems, NULL);
2106
2078
                }
2107
2079
        }
2108
 
        NODEMASK_FREE(oldmems);
2109
2080
}
2110
2081
 
2111
2082
/*
2147
2118
static int cpuset_track_online_nodes(struct notifier_block *self,
2148
2119
                                unsigned long action, void *arg)
2149
2120
{
2150
 
        NODEMASK_ALLOC(nodemask_t, oldmems, GFP_KERNEL);
2151
 
 
2152
 
        if (oldmems == NULL)
2153
 
                return NOTIFY_DONE;
 
2121
        static nodemask_t oldmems;      /* protected by cgroup_mutex */
2154
2122
 
2155
2123
        cgroup_lock();
2156
2124
        switch (action) {
2157
2125
        case MEM_ONLINE:
2158
 
                *oldmems = top_cpuset.mems_allowed;
 
2126
                oldmems = top_cpuset.mems_allowed;
2159
2127
                mutex_lock(&callback_mutex);
2160
2128
                top_cpuset.mems_allowed = node_states[N_HIGH_MEMORY];
2161
2129
                mutex_unlock(&callback_mutex);
2162
 
                update_tasks_nodemask(&top_cpuset, oldmems, NULL);
 
2130
                update_tasks_nodemask(&top_cpuset, &oldmems, NULL);
2163
2131
                break;
2164
2132
        case MEM_OFFLINE:
2165
2133
                /*
2173
2141
        }
2174
2142
        cgroup_unlock();
2175
2143
 
2176
 
        NODEMASK_FREE(oldmems);
2177
2144
        return NOTIFY_OK;
2178
2145
}
2179
2146
#endif
2223
2190
        rcu_read_lock();
2224
2191
        cs = task_cs(tsk);
2225
2192
        if (cs)
2226
 
                cpumask_copy(&tsk->cpus_allowed, cs->cpus_allowed);
 
2193
                do_set_cpus_allowed(tsk, cs->cpus_allowed);
2227
2194
        rcu_read_unlock();
2228
2195
 
2229
2196
        /*
2250
2217
                 * Like above we can temporary set any mask and rely on
2251
2218
                 * set_cpus_allowed_ptr() as synchronization point.
2252
2219
                 */
2253
 
                cpumask_copy(&tsk->cpus_allowed, cpu_possible_mask);
 
2220
                do_set_cpus_allowed(tsk, cpu_possible_mask);
2254
2221
                cpu = cpumask_any(cpu_active_mask);
2255
2222
        }
2256
2223