Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sysctl: Move jiffies converters to kernel/time/jiffies.c

Move integer jiffies converters (proc_dointvec{_,_ms_,_userhz_}jiffies
and proc_dointvec_ms_jiffies_minmax) to kernel/time/jiffies.c. Error
stubs for when CONFIG_PRCO_SYSCTL is not defined are not reproduced
because all the jiffies converters go through proc_dointvec_conv which
is already stubbed. This is part of the greater effort to move sysctl
logic out of kernel/sysctl.c thereby reducing merge conflicts in
kernel/sysctl.c.

Signed-off-by: Joel Granados <joel.granados@kernel.org>

+110 -131
+10
include/linux/jiffies.h
··· 611 611 612 612 #define TIMESTAMP_SIZE 30 613 613 614 + struct ctl_table; 615 + int proc_dointvec_jiffies(const struct ctl_table *table, int dir, void *buffer, 616 + size_t *lenp, loff_t *ppos); 617 + int proc_dointvec_ms_jiffies_minmax(const struct ctl_table *table, int dir, 618 + void *buffer, size_t *lenp, loff_t *ppos); 619 + int proc_dointvec_userhz_jiffies(const struct ctl_table *table, int dir, 620 + void *buffer, size_t *lenp, loff_t *ppos); 621 + int proc_dointvec_ms_jiffies(const struct ctl_table *table, int dir, void *buffer, 622 + size_t *lenp, loff_t *ppos); 623 + 614 624 #endif
-7
include/linux/sysctl.h
··· 192 192 size_t *lenp, loff_t *ppos); 193 193 int proc_dou8vec_minmax(const struct ctl_table *table, int write, void *buffer, 194 194 size_t *lenp, loff_t *ppos); 195 - int proc_dointvec_jiffies(const struct ctl_table *, int, void *, size_t *, loff_t *); 196 - int proc_dointvec_ms_jiffies_minmax(const struct ctl_table *table, int write, 197 - void *buffer, size_t *lenp, loff_t *ppos); 198 - int proc_dointvec_userhz_jiffies(const struct ctl_table *, int, void *, size_t *, 199 - loff_t *); 200 - int proc_dointvec_ms_jiffies(const struct ctl_table *, int, void *, size_t *, 201 - loff_t *); 202 195 int proc_doulongvec_minmax(const struct ctl_table *, int, void *, size_t *, loff_t *); 203 196 int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int, void *, 204 197 size_t *, loff_t *);
-124
kernel/sysctl.c
··· 356 356 } 357 357 358 358 #define SYSCTL_CONV_IDENTITY(val) val 359 - #define SYSCTL_CONV_MULT_HZ(val) ((val) * HZ) 360 - #define SYSCTL_CONV_DIV_HZ(val) ((val) / HZ) 361 359 362 360 static SYSCTL_USER_TO_KERN_INT_CONV(, SYSCTL_CONV_IDENTITY) 363 361 static SYSCTL_KERN_TO_USER_INT_CONV(, SYSCTL_CONV_IDENTITY) 364 362 365 - static SYSCTL_USER_TO_KERN_INT_CONV(_hz, SYSCTL_CONV_MULT_HZ) 366 - static SYSCTL_KERN_TO_USER_INT_CONV(_hz, SYSCTL_CONV_DIV_HZ) 367 - 368 - static SYSCTL_USER_TO_KERN_INT_CONV(_userhz, clock_t_to_jiffies) 369 - static SYSCTL_KERN_TO_USER_INT_CONV(_userhz, jiffies_to_clock_t) 370 - 371 - static SYSCTL_USER_TO_KERN_INT_CONV(_ms, msecs_to_jiffies) 372 - static SYSCTL_KERN_TO_USER_INT_CONV(_ms, jiffies_to_msecs) 373 - 374 363 static SYSCTL_INT_CONV_CUSTOM(, sysctl_user_to_kern_int_conv, 375 364 sysctl_kern_to_user_int_conv, false) 376 - static SYSCTL_INT_CONV_CUSTOM(_jiffies, sysctl_user_to_kern_int_conv_hz, 377 - sysctl_kern_to_user_int_conv_hz, false) 378 - static SYSCTL_INT_CONV_CUSTOM(_userhz_jiffies, 379 - sysctl_user_to_kern_int_conv_userhz, 380 - sysctl_kern_to_user_int_conv_userhz, false) 381 - static SYSCTL_INT_CONV_CUSTOM(_ms_jiffies, sysctl_user_to_kern_int_conv_ms, 382 - sysctl_kern_to_user_int_conv_ms, false) 383 - 384 365 static SYSCTL_INT_CONV_CUSTOM(_minmax, sysctl_user_to_kern_int_conv, 385 366 sysctl_kern_to_user_int_conv, true) 386 - static SYSCTL_INT_CONV_CUSTOM(_ms_jiffies_minmax, 387 - sysctl_user_to_kern_int_conv_ms, 388 - sysctl_kern_to_user_int_conv_ms, true) 389 367 390 368 391 369 static SYSCTL_USER_TO_KERN_UINT_CONV(, SYSCTL_CONV_IDENTITY) ··· 880 902 } 881 903 882 904 /** 883 - * proc_dointvec_jiffies - read a vector of integers as seconds 884 - * @table: the sysctl table 885 - * @dir: %TRUE if this is a write to the sysctl file 886 - * @buffer: the user buffer 887 - * @lenp: the size of the user buffer 888 - * @ppos: file position 889 - * 890 - * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 891 - * values from/to the user buffer, treated as an ASCII string. 892 - * The values read are assumed to be in seconds, and are converted into 893 - * jiffies. 894 - * 895 - * Returns 0 on success. 896 - */ 897 - int proc_dointvec_jiffies(const struct ctl_table *table, int dir, 898 - void *buffer, size_t *lenp, loff_t *ppos) 899 - { 900 - return proc_dointvec_conv(table, dir, buffer, lenp, ppos, 901 - do_proc_int_conv_jiffies); 902 - } 903 - 904 - int proc_dointvec_ms_jiffies_minmax(const struct ctl_table *table, int dir, 905 - void *buffer, size_t *lenp, loff_t *ppos) 906 - { 907 - return proc_dointvec_conv(table, dir, buffer, lenp, ppos, 908 - do_proc_int_conv_ms_jiffies_minmax); 909 - } 910 - 911 - /** 912 - * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds 913 - * @table: the sysctl table 914 - * @dir: %TRUE if this is a write to the sysctl file 915 - * @buffer: the user buffer 916 - * @lenp: the size of the user buffer 917 - * @ppos: pointer to the file position 918 - * 919 - * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 920 - * values from/to the user buffer, treated as an ASCII string. 921 - * The values read are assumed to be in 1/USER_HZ seconds, and 922 - * are converted into jiffies. 923 - * 924 - * Returns 0 on success. 925 - */ 926 - int proc_dointvec_userhz_jiffies(const struct ctl_table *table, int dir, 927 - void *buffer, size_t *lenp, loff_t *ppos) 928 - { 929 - if (SYSCTL_USER_TO_KERN(dir) && USER_HZ < HZ) 930 - return -EINVAL; 931 - return proc_dointvec_conv(table, dir, buffer, lenp, ppos, 932 - do_proc_int_conv_userhz_jiffies); 933 - } 934 - 935 - /** 936 - * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds 937 - * @table: the sysctl table 938 - * @dir: %TRUE if this is a write to the sysctl file 939 - * @buffer: the user buffer 940 - * @lenp: the size of the user buffer 941 - * @ppos: the current position in the file 942 - * 943 - * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 944 - * values from/to the user buffer, treated as an ASCII string. 945 - * The values read are assumed to be in 1/1000 seconds, and 946 - * are converted into jiffies. 947 - * 948 - * Returns 0 on success. 949 - */ 950 - int proc_dointvec_ms_jiffies(const struct ctl_table *table, int dir, void *buffer, 951 - size_t *lenp, loff_t *ppos) 952 - { 953 - return proc_dointvec_conv(table, dir, buffer, lenp, ppos, 954 - do_proc_int_conv_ms_jiffies); 955 - } 956 - 957 - /** 958 905 * proc_do_large_bitmap - read/write from/to a large bitmap 959 906 * @table: the sysctl table 960 907 * @dir: %TRUE if this is a write to the sysctl file ··· 1070 1167 return -ENOSYS; 1071 1168 } 1072 1169 1073 - int proc_dointvec_jiffies(const struct ctl_table *table, int dir, 1074 - void *buffer, size_t *lenp, loff_t *ppos) 1075 - { 1076 - return -ENOSYS; 1077 - } 1078 - 1079 - int proc_dointvec_ms_jiffies_minmax(const struct ctl_table *table, int dir, 1080 - void *buffer, size_t *lenp, loff_t *ppos) 1081 - { 1082 - return -ENOSYS; 1083 - } 1084 - 1085 - int proc_dointvec_userhz_jiffies(const struct ctl_table *table, int dir, 1086 - void *buffer, size_t *lenp, loff_t *ppos) 1087 - { 1088 - return -ENOSYS; 1089 - } 1090 - 1091 - int proc_dointvec_ms_jiffies(const struct ctl_table *table, int dir, 1092 - void *buffer, size_t *lenp, loff_t *ppos) 1093 - { 1094 - return -ENOSYS; 1095 - } 1096 - 1097 1170 int proc_doulongvec_minmax(const struct ctl_table *table, int dir, 1098 1171 void *buffer, size_t *lenp, loff_t *ppos) 1099 1172 { ··· 1189 1310 EXPORT_SYMBOL(proc_dobool); 1190 1311 EXPORT_SYMBOL(proc_dointvec); 1191 1312 EXPORT_SYMBOL(proc_douintvec); 1192 - EXPORT_SYMBOL(proc_dointvec_jiffies); 1193 1313 EXPORT_SYMBOL(proc_dointvec_minmax); 1194 1314 EXPORT_SYMBOL_GPL(proc_douintvec_minmax); 1195 - EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); 1196 - EXPORT_SYMBOL(proc_dointvec_ms_jiffies); 1197 1315 EXPORT_SYMBOL(proc_dostring); 1198 1316 EXPORT_SYMBOL(proc_doulongvec_minmax); 1199 1317 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
+100
kernel/time/jiffies.c
··· 99 99 100 100 __clocksource_register(&refined_jiffies); 101 101 } 102 + 103 + #define SYSCTL_CONV_MULT_HZ(val) ((val) * HZ) 104 + #define SYSCTL_CONV_DIV_HZ(val) ((val) / HZ) 105 + 106 + static SYSCTL_USER_TO_KERN_INT_CONV(_hz, SYSCTL_CONV_MULT_HZ) 107 + static SYSCTL_KERN_TO_USER_INT_CONV(_hz, SYSCTL_CONV_DIV_HZ) 108 + static SYSCTL_USER_TO_KERN_INT_CONV(_userhz, clock_t_to_jiffies) 109 + static SYSCTL_KERN_TO_USER_INT_CONV(_userhz, jiffies_to_clock_t) 110 + static SYSCTL_USER_TO_KERN_INT_CONV(_ms, msecs_to_jiffies) 111 + static SYSCTL_KERN_TO_USER_INT_CONV(_ms, jiffies_to_msecs) 112 + 113 + static SYSCTL_INT_CONV_CUSTOM(_jiffies, sysctl_user_to_kern_int_conv_hz, 114 + sysctl_kern_to_user_int_conv_hz, false) 115 + static SYSCTL_INT_CONV_CUSTOM(_userhz_jiffies, 116 + sysctl_user_to_kern_int_conv_userhz, 117 + sysctl_kern_to_user_int_conv_userhz, false) 118 + static SYSCTL_INT_CONV_CUSTOM(_ms_jiffies, sysctl_user_to_kern_int_conv_ms, 119 + sysctl_kern_to_user_int_conv_ms, false) 120 + static SYSCTL_INT_CONV_CUSTOM(_ms_jiffies_minmax, 121 + sysctl_user_to_kern_int_conv_ms, 122 + sysctl_kern_to_user_int_conv_ms, true) 123 + 124 + /** 125 + * proc_dointvec_jiffies - read a vector of integers as seconds 126 + * @table: the sysctl table 127 + * @dir: %TRUE if this is a write to the sysctl file 128 + * @buffer: the user buffer 129 + * @lenp: the size of the user buffer 130 + * @ppos: file position 131 + * 132 + * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 133 + * values from/to the user buffer, treated as an ASCII string. 134 + * The values read are assumed to be in seconds, and are converted into 135 + * jiffies. 136 + * 137 + * Returns 0 on success. 138 + */ 139 + int proc_dointvec_jiffies(const struct ctl_table *table, int dir, 140 + void *buffer, size_t *lenp, loff_t *ppos) 141 + { 142 + return proc_dointvec_conv(table, dir, buffer, lenp, ppos, 143 + do_proc_int_conv_jiffies); 144 + } 145 + EXPORT_SYMBOL(proc_dointvec_jiffies); 146 + 147 + /** 148 + * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds 149 + * @table: the sysctl table 150 + * @dir: %TRUE if this is a write to the sysctl file 151 + * @buffer: the user buffer 152 + * @lenp: the size of the user buffer 153 + * @ppos: pointer to the file position 154 + * 155 + * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 156 + * values from/to the user buffer, treated as an ASCII string. 157 + * The values read are assumed to be in 1/USER_HZ seconds, and 158 + * are converted into jiffies. 159 + * 160 + * Returns 0 on success. 161 + */ 162 + int proc_dointvec_userhz_jiffies(const struct ctl_table *table, int dir, 163 + void *buffer, size_t *lenp, loff_t *ppos) 164 + { 165 + if (SYSCTL_USER_TO_KERN(dir) && USER_HZ < HZ) 166 + return -EINVAL; 167 + return proc_dointvec_conv(table, dir, buffer, lenp, ppos, 168 + do_proc_int_conv_userhz_jiffies); 169 + } 170 + EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); 171 + 172 + /** 173 + * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds 174 + * @table: the sysctl table 175 + * @dir: %TRUE if this is a write to the sysctl file 176 + * @buffer: the user buffer 177 + * @lenp: the size of the user buffer 178 + * @ppos: the current position in the file 179 + * 180 + * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 181 + * values from/to the user buffer, treated as an ASCII string. 182 + * The values read are assumed to be in 1/1000 seconds, and 183 + * are converted into jiffies. 184 + * 185 + * Returns 0 on success. 186 + */ 187 + int proc_dointvec_ms_jiffies(const struct ctl_table *table, int dir, void *buffer, 188 + size_t *lenp, loff_t *ppos) 189 + { 190 + return proc_dointvec_conv(table, dir, buffer, lenp, ppos, 191 + do_proc_int_conv_ms_jiffies); 192 + } 193 + 194 + int proc_dointvec_ms_jiffies_minmax(const struct ctl_table *table, int dir, 195 + void *buffer, size_t *lenp, loff_t *ppos) 196 + { 197 + return proc_dointvec_conv(table, dir, buffer, lenp, ppos, 198 + do_proc_int_conv_ms_jiffies_minmax); 199 + } 200 + EXPORT_SYMBOL(proc_dointvec_ms_jiffies); 201 +