函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:kernel\sched\core.c Create Date:2022-07-27 10:36:22
首页 Copyright©Brick

2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
#ifdef CONFIG_NUMA_BALANCING
 
void set_numabalancing_state(bool enabled)
{
    if (enabled)
        static_branch_enable(&sched_numa_balancing);
    else
        static_branch_disable(&sched_numa_balancing);
}
 
#ifdef CONFIG_PROC_SYSCTL
int sysctl_numa_balancing(struct ctl_table *table, int write,
             void __user *buffer, size_t *lenp, loff_t *ppos)
{
    struct ctl_table t;
    int err;
    int state = static_branch_likely(&sched_numa_balancing);
 
    if (write && !capable(CAP_SYS_ADMIN))
        return -EPERM;
 
    t = *table;
    t.data = &state;
    err = proc_dointvec_minmax(&t, write, buffer, lenp, ppos);
    if (err < 0)
        return err;
    if (write)
        set_numabalancing_state(state);
    return err;
}
#endif
#endif
 
#ifdef CONFIG_SCHEDSTATS
 
DEFINE_STATIC_KEY_FALSE(sched_schedstats);
static bool __initdata __sched_schedstats = false;
 
static void set_schedstats(bool enabled)
{
    if (enabled)
        static_branch_enable(&sched_schedstats);
    else
        static_branch_disable(&sched_schedstats);
}
 
void force_schedstat_enabled(void)
{
    if (!schedstat_enabled()) {
        pr_info("kernel profiling enabled schedstats, disable via kernel.sched_schedstats.\n");
        static_branch_enable(&sched_schedstats);
    }
}
 
static int __init setup_schedstats(char *str)
{
    int ret = 0;
    if (!str)
        goto out;
 
    /*
     * This code is called before jump labels have been set up, so we can't
     * change the static branch directly just yet.  Instead set a temporary
     * variable so init_schedstats() can do it later.
     */
    if (!strcmp(str, "enable")) {
        __sched_schedstats = true;
        ret = 1;
    } else if (!strcmp(str, "disable")) {
        __sched_schedstats = false;
        ret = 1;
    }
out:
    if (!ret)
        pr_warn("Unable to parse schedstats=\n");
 
    return ret;
}
__setup("schedstats=", setup_schedstats);
 
static void __init init_schedstats(void)
{
    set_schedstats(__sched_schedstats);
}
 
#ifdef CONFIG_PROC_SYSCTL
int sysctl_schedstats(struct ctl_table *table, int write,
             void __user *buffer, size_t *lenp, loff_t *ppos)
{
    struct ctl_table t;
    int err;
    int state = static_branch_likely(&sched_schedstats);
 
    if (write && !capable(CAP_SYS_ADMIN))
        return -EPERM;
 
    t = *table;
    t.data = &state;
    err = proc_dointvec_minmax(&t, write, buffer, lenp, ppos);
    if (err < 0)
        return err;
    if (write)
        set_schedstats(state);
    return err;
}
#endif /* CONFIG_PROC_SYSCTL */
#else  /* !CONFIG_SCHEDSTATS */
static inline void init_schedstats(void) {}