processor_throttling.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324
  1. /*
  2. * processor_throttling.c - Throttling submodule of the ACPI processor driver
  3. *
  4. * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  5. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  6. * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de>
  7. * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
  8. * - Added processor hotplug support
  9. *
  10. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or (at
  15. * your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful, but
  18. * WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License along
  23. * with this program; if not, write to the Free Software Foundation, Inc.,
  24. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  25. *
  26. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. */
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/init.h>
  31. #include <linux/sched.h>
  32. #include <linux/cpufreq.h>
  33. #include <linux/proc_fs.h>
  34. #include <linux/seq_file.h>
  35. #include <asm/io.h>
  36. #include <asm/uaccess.h>
  37. #include <acpi/acpi_bus.h>
  38. #include <acpi/acpi_drivers.h>
  39. #include <acpi/processor.h>
  40. #define ACPI_PROCESSOR_CLASS "processor"
  41. #define _COMPONENT ACPI_PROCESSOR_COMPONENT
  42. ACPI_MODULE_NAME("processor_throttling");
  43. /* ignore_tpc:
  44. * 0 -> acpi processor driver doesn't ignore _TPC values
  45. * 1 -> acpi processor driver ignores _TPC values
  46. */
  47. static int ignore_tpc;
  48. module_param(ignore_tpc, int, 0644);
  49. MODULE_PARM_DESC(ignore_tpc, "Disable broken BIOS _TPC throttling support");
  50. struct throttling_tstate {
  51. unsigned int cpu; /* cpu nr */
  52. int target_state; /* target T-state */
  53. };
  54. #define THROTTLING_PRECHANGE (1)
  55. #define THROTTLING_POSTCHANGE (2)
  56. static int acpi_processor_get_throttling(struct acpi_processor *pr);
  57. int acpi_processor_set_throttling(struct acpi_processor *pr, int state);
  58. static int acpi_processor_update_tsd_coord(void)
  59. {
  60. int count, count_target;
  61. int retval = 0;
  62. unsigned int i, j;
  63. cpumask_var_t covered_cpus;
  64. struct acpi_processor *pr, *match_pr;
  65. struct acpi_tsd_package *pdomain, *match_pdomain;
  66. struct acpi_processor_throttling *pthrottling, *match_pthrottling;
  67. if (!alloc_cpumask_var(&covered_cpus, GFP_KERNEL))
  68. return -ENOMEM;
  69. /*
  70. * Now that we have _TSD data from all CPUs, lets setup T-state
  71. * coordination between all CPUs.
  72. */
  73. for_each_possible_cpu(i) {
  74. pr = per_cpu(processors, i);
  75. if (!pr)
  76. continue;
  77. /* Basic validity check for domain info */
  78. pthrottling = &(pr->throttling);
  79. /*
  80. * If tsd package for one cpu is invalid, the coordination
  81. * among all CPUs is thought as invalid.
  82. * Maybe it is ugly.
  83. */
  84. if (!pthrottling->tsd_valid_flag) {
  85. retval = -EINVAL;
  86. break;
  87. }
  88. }
  89. if (retval)
  90. goto err_ret;
  91. cpumask_clear(covered_cpus);
  92. for_each_possible_cpu(i) {
  93. pr = per_cpu(processors, i);
  94. if (!pr)
  95. continue;
  96. if (cpumask_test_cpu(i, covered_cpus))
  97. continue;
  98. pthrottling = &pr->throttling;
  99. pdomain = &(pthrottling->domain_info);
  100. cpumask_set_cpu(i, pthrottling->shared_cpu_map);
  101. cpumask_set_cpu(i, covered_cpus);
  102. /*
  103. * If the number of processor in the TSD domain is 1, it is
  104. * unnecessary to parse the coordination for this CPU.
  105. */
  106. if (pdomain->num_processors <= 1)
  107. continue;
  108. /* Validate the Domain info */
  109. count_target = pdomain->num_processors;
  110. count = 1;
  111. for_each_possible_cpu(j) {
  112. if (i == j)
  113. continue;
  114. match_pr = per_cpu(processors, j);
  115. if (!match_pr)
  116. continue;
  117. match_pthrottling = &(match_pr->throttling);
  118. match_pdomain = &(match_pthrottling->domain_info);
  119. if (match_pdomain->domain != pdomain->domain)
  120. continue;
  121. /* Here i and j are in the same domain.
  122. * If two TSD packages have the same domain, they
  123. * should have the same num_porcessors and
  124. * coordination type. Otherwise it will be regarded
  125. * as illegal.
  126. */
  127. if (match_pdomain->num_processors != count_target) {
  128. retval = -EINVAL;
  129. goto err_ret;
  130. }
  131. if (pdomain->coord_type != match_pdomain->coord_type) {
  132. retval = -EINVAL;
  133. goto err_ret;
  134. }
  135. cpumask_set_cpu(j, covered_cpus);
  136. cpumask_set_cpu(j, pthrottling->shared_cpu_map);
  137. count++;
  138. }
  139. for_each_possible_cpu(j) {
  140. if (i == j)
  141. continue;
  142. match_pr = per_cpu(processors, j);
  143. if (!match_pr)
  144. continue;
  145. match_pthrottling = &(match_pr->throttling);
  146. match_pdomain = &(match_pthrottling->domain_info);
  147. if (match_pdomain->domain != pdomain->domain)
  148. continue;
  149. /*
  150. * If some CPUS have the same domain, they
  151. * will have the same shared_cpu_map.
  152. */
  153. cpumask_copy(match_pthrottling->shared_cpu_map,
  154. pthrottling->shared_cpu_map);
  155. }
  156. }
  157. err_ret:
  158. free_cpumask_var(covered_cpus);
  159. for_each_possible_cpu(i) {
  160. pr = per_cpu(processors, i);
  161. if (!pr)
  162. continue;
  163. /*
  164. * Assume no coordination on any error parsing domain info.
  165. * The coordination type will be forced as SW_ALL.
  166. */
  167. if (retval) {
  168. pthrottling = &(pr->throttling);
  169. cpumask_clear(pthrottling->shared_cpu_map);
  170. cpumask_set_cpu(i, pthrottling->shared_cpu_map);
  171. pthrottling->shared_type = DOMAIN_COORD_TYPE_SW_ALL;
  172. }
  173. }
  174. return retval;
  175. }
  176. /*
  177. * Update the T-state coordination after the _TSD
  178. * data for all cpus is obtained.
  179. */
  180. void acpi_processor_throttling_init(void)
  181. {
  182. if (acpi_processor_update_tsd_coord())
  183. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  184. "Assume no T-state coordination\n"));
  185. return;
  186. }
  187. static int acpi_processor_throttling_notifier(unsigned long event, void *data)
  188. {
  189. struct throttling_tstate *p_tstate = data;
  190. struct acpi_processor *pr;
  191. unsigned int cpu ;
  192. int target_state;
  193. struct acpi_processor_limit *p_limit;
  194. struct acpi_processor_throttling *p_throttling;
  195. cpu = p_tstate->cpu;
  196. pr = per_cpu(processors, cpu);
  197. if (!pr) {
  198. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid pr pointer\n"));
  199. return 0;
  200. }
  201. if (!pr->flags.throttling) {
  202. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Throttling control is "
  203. "unsupported on CPU %d\n", cpu));
  204. return 0;
  205. }
  206. target_state = p_tstate->target_state;
  207. p_throttling = &(pr->throttling);
  208. switch (event) {
  209. case THROTTLING_PRECHANGE:
  210. /*
  211. * Prechange event is used to choose one proper t-state,
  212. * which meets the limits of thermal, user and _TPC.
  213. */
  214. p_limit = &pr->limit;
  215. if (p_limit->thermal.tx > target_state)
  216. target_state = p_limit->thermal.tx;
  217. if (p_limit->user.tx > target_state)
  218. target_state = p_limit->user.tx;
  219. if (pr->throttling_platform_limit > target_state)
  220. target_state = pr->throttling_platform_limit;
  221. if (target_state >= p_throttling->state_count) {
  222. printk(KERN_WARNING
  223. "Exceed the limit of T-state \n");
  224. target_state = p_throttling->state_count - 1;
  225. }
  226. p_tstate->target_state = target_state;
  227. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PreChange Event:"
  228. "target T-state of CPU %d is T%d\n",
  229. cpu, target_state));
  230. break;
  231. case THROTTLING_POSTCHANGE:
  232. /*
  233. * Postchange event is only used to update the
  234. * T-state flag of acpi_processor_throttling.
  235. */
  236. p_throttling->state = target_state;
  237. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PostChange Event:"
  238. "CPU %d is switched to T%d\n",
  239. cpu, target_state));
  240. break;
  241. default:
  242. printk(KERN_WARNING
  243. "Unsupported Throttling notifier event\n");
  244. break;
  245. }
  246. return 0;
  247. }
  248. /*
  249. * _TPC - Throttling Present Capabilities
  250. */
  251. static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
  252. {
  253. acpi_status status = 0;
  254. unsigned long long tpc = 0;
  255. if (!pr)
  256. return -EINVAL;
  257. if (ignore_tpc)
  258. goto end;
  259. status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc);
  260. if (ACPI_FAILURE(status)) {
  261. if (status != AE_NOT_FOUND) {
  262. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC"));
  263. }
  264. return -ENODEV;
  265. }
  266. end:
  267. pr->throttling_platform_limit = (int)tpc;
  268. return 0;
  269. }
  270. int acpi_processor_tstate_has_changed(struct acpi_processor *pr)
  271. {
  272. int result = 0;
  273. int throttling_limit;
  274. int current_state;
  275. struct acpi_processor_limit *limit;
  276. int target_state;
  277. if (ignore_tpc)
  278. return 0;
  279. result = acpi_processor_get_platform_limit(pr);
  280. if (result) {
  281. /* Throttling Limit is unsupported */
  282. return result;
  283. }
  284. throttling_limit = pr->throttling_platform_limit;
  285. if (throttling_limit >= pr->throttling.state_count) {
  286. /* Uncorrect Throttling Limit */
  287. return -EINVAL;
  288. }
  289. current_state = pr->throttling.state;
  290. if (current_state > throttling_limit) {
  291. /*
  292. * The current state can meet the requirement of
  293. * _TPC limit. But it is reasonable that OSPM changes
  294. * t-states from high to low for better performance.
  295. * Of course the limit condition of thermal
  296. * and user should be considered.
  297. */
  298. limit = &pr->limit;
  299. target_state = throttling_limit;
  300. if (limit->thermal.tx > target_state)
  301. target_state = limit->thermal.tx;
  302. if (limit->user.tx > target_state)
  303. target_state = limit->user.tx;
  304. } else if (current_state == throttling_limit) {
  305. /*
  306. * Unnecessary to change the throttling state
  307. */
  308. return 0;
  309. } else {
  310. /*
  311. * If the current state is lower than the limit of _TPC, it
  312. * will be forced to switch to the throttling state defined
  313. * by throttling_platfor_limit.
  314. * Because the previous state meets with the limit condition
  315. * of thermal and user, it is unnecessary to check it again.
  316. */
  317. target_state = throttling_limit;
  318. }
  319. return acpi_processor_set_throttling(pr, target_state);
  320. }
  321. /*
  322. * _PTC - Processor Throttling Control (and status) register location
  323. */
  324. static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
  325. {
  326. int result = 0;
  327. acpi_status status = 0;
  328. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  329. union acpi_object *ptc = NULL;
  330. union acpi_object obj = { 0 };
  331. struct acpi_processor_throttling *throttling;
  332. status = acpi_evaluate_object(pr->handle, "_PTC", NULL, &buffer);
  333. if (ACPI_FAILURE(status)) {
  334. if (status != AE_NOT_FOUND) {
  335. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PTC"));
  336. }
  337. return -ENODEV;
  338. }
  339. ptc = (union acpi_object *)buffer.pointer;
  340. if (!ptc || (ptc->type != ACPI_TYPE_PACKAGE)
  341. || (ptc->package.count != 2)) {
  342. printk(KERN_ERR PREFIX "Invalid _PTC data\n");
  343. result = -EFAULT;
  344. goto end;
  345. }
  346. /*
  347. * control_register
  348. */
  349. obj = ptc->package.elements[0];
  350. if ((obj.type != ACPI_TYPE_BUFFER)
  351. || (obj.buffer.length < sizeof(struct acpi_ptc_register))
  352. || (obj.buffer.pointer == NULL)) {
  353. printk(KERN_ERR PREFIX
  354. "Invalid _PTC data (control_register)\n");
  355. result = -EFAULT;
  356. goto end;
  357. }
  358. memcpy(&pr->throttling.control_register, obj.buffer.pointer,
  359. sizeof(struct acpi_ptc_register));
  360. /*
  361. * status_register
  362. */
  363. obj = ptc->package.elements[1];
  364. if ((obj.type != ACPI_TYPE_BUFFER)
  365. || (obj.buffer.length < sizeof(struct acpi_ptc_register))
  366. || (obj.buffer.pointer == NULL)) {
  367. printk(KERN_ERR PREFIX "Invalid _PTC data (status_register)\n");
  368. result = -EFAULT;
  369. goto end;
  370. }
  371. memcpy(&pr->throttling.status_register, obj.buffer.pointer,
  372. sizeof(struct acpi_ptc_register));
  373. throttling = &pr->throttling;
  374. if ((throttling->control_register.bit_width +
  375. throttling->control_register.bit_offset) > 32) {
  376. printk(KERN_ERR PREFIX "Invalid _PTC control register\n");
  377. result = -EFAULT;
  378. goto end;
  379. }
  380. if ((throttling->status_register.bit_width +
  381. throttling->status_register.bit_offset) > 32) {
  382. printk(KERN_ERR PREFIX "Invalid _PTC status register\n");
  383. result = -EFAULT;
  384. goto end;
  385. }
  386. end:
  387. kfree(buffer.pointer);
  388. return result;
  389. }
  390. /*
  391. * _TSS - Throttling Supported States
  392. */
  393. static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
  394. {
  395. int result = 0;
  396. acpi_status status = AE_OK;
  397. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  398. struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" };
  399. struct acpi_buffer state = { 0, NULL };
  400. union acpi_object *tss = NULL;
  401. int i;
  402. status = acpi_evaluate_object(pr->handle, "_TSS", NULL, &buffer);
  403. if (ACPI_FAILURE(status)) {
  404. if (status != AE_NOT_FOUND) {
  405. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSS"));
  406. }
  407. return -ENODEV;
  408. }
  409. tss = buffer.pointer;
  410. if (!tss || (tss->type != ACPI_TYPE_PACKAGE)) {
  411. printk(KERN_ERR PREFIX "Invalid _TSS data\n");
  412. result = -EFAULT;
  413. goto end;
  414. }
  415. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
  416. tss->package.count));
  417. pr->throttling.state_count = tss->package.count;
  418. pr->throttling.states_tss =
  419. kmalloc(sizeof(struct acpi_processor_tx_tss) * tss->package.count,
  420. GFP_KERNEL);
  421. if (!pr->throttling.states_tss) {
  422. result = -ENOMEM;
  423. goto end;
  424. }
  425. for (i = 0; i < pr->throttling.state_count; i++) {
  426. struct acpi_processor_tx_tss *tx =
  427. (struct acpi_processor_tx_tss *)&(pr->throttling.
  428. states_tss[i]);
  429. state.length = sizeof(struct acpi_processor_tx_tss);
  430. state.pointer = tx;
  431. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i));
  432. status = acpi_extract_package(&(tss->package.elements[i]),
  433. &format, &state);
  434. if (ACPI_FAILURE(status)) {
  435. ACPI_EXCEPTION((AE_INFO, status, "Invalid _TSS data"));
  436. result = -EFAULT;
  437. kfree(pr->throttling.states_tss);
  438. goto end;
  439. }
  440. if (!tx->freqpercentage) {
  441. printk(KERN_ERR PREFIX
  442. "Invalid _TSS data: freq is zero\n");
  443. result = -EFAULT;
  444. kfree(pr->throttling.states_tss);
  445. goto end;
  446. }
  447. }
  448. end:
  449. kfree(buffer.pointer);
  450. return result;
  451. }
  452. /*
  453. * _TSD - T-State Dependencies
  454. */
  455. static int acpi_processor_get_tsd(struct acpi_processor *pr)
  456. {
  457. int result = 0;
  458. acpi_status status = AE_OK;
  459. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  460. struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" };
  461. struct acpi_buffer state = { 0, NULL };
  462. union acpi_object *tsd = NULL;
  463. struct acpi_tsd_package *pdomain;
  464. struct acpi_processor_throttling *pthrottling;
  465. pthrottling = &pr->throttling;
  466. pthrottling->tsd_valid_flag = 0;
  467. status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer);
  468. if (ACPI_FAILURE(status)) {
  469. if (status != AE_NOT_FOUND) {
  470. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSD"));
  471. }
  472. return -ENODEV;
  473. }
  474. tsd = buffer.pointer;
  475. if (!tsd || (tsd->type != ACPI_TYPE_PACKAGE)) {
  476. printk(KERN_ERR PREFIX "Invalid _TSD data\n");
  477. result = -EFAULT;
  478. goto end;
  479. }
  480. if (tsd->package.count != 1) {
  481. printk(KERN_ERR PREFIX "Invalid _TSD data\n");
  482. result = -EFAULT;
  483. goto end;
  484. }
  485. pdomain = &(pr->throttling.domain_info);
  486. state.length = sizeof(struct acpi_tsd_package);
  487. state.pointer = pdomain;
  488. status = acpi_extract_package(&(tsd->package.elements[0]),
  489. &format, &state);
  490. if (ACPI_FAILURE(status)) {
  491. printk(KERN_ERR PREFIX "Invalid _TSD data\n");
  492. result = -EFAULT;
  493. goto end;
  494. }
  495. if (pdomain->num_entries != ACPI_TSD_REV0_ENTRIES) {
  496. printk(KERN_ERR PREFIX "Unknown _TSD:num_entries\n");
  497. result = -EFAULT;
  498. goto end;
  499. }
  500. if (pdomain->revision != ACPI_TSD_REV0_REVISION) {
  501. printk(KERN_ERR PREFIX "Unknown _TSD:revision\n");
  502. result = -EFAULT;
  503. goto end;
  504. }
  505. pthrottling = &pr->throttling;
  506. pthrottling->tsd_valid_flag = 1;
  507. pthrottling->shared_type = pdomain->coord_type;
  508. cpumask_set_cpu(pr->id, pthrottling->shared_cpu_map);
  509. /*
  510. * If the coordination type is not defined in ACPI spec,
  511. * the tsd_valid_flag will be clear and coordination type
  512. * will be forecd as DOMAIN_COORD_TYPE_SW_ALL.
  513. */
  514. if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL &&
  515. pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY &&
  516. pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) {
  517. pthrottling->tsd_valid_flag = 0;
  518. pthrottling->shared_type = DOMAIN_COORD_TYPE_SW_ALL;
  519. }
  520. end:
  521. kfree(buffer.pointer);
  522. return result;
  523. }
  524. /* --------------------------------------------------------------------------
  525. Throttling Control
  526. -------------------------------------------------------------------------- */
  527. static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr)
  528. {
  529. int state = 0;
  530. u32 value = 0;
  531. u32 duty_mask = 0;
  532. u32 duty_value = 0;
  533. if (!pr)
  534. return -EINVAL;
  535. if (!pr->flags.throttling)
  536. return -ENODEV;
  537. pr->throttling.state = 0;
  538. duty_mask = pr->throttling.state_count - 1;
  539. duty_mask <<= pr->throttling.duty_offset;
  540. local_irq_disable();
  541. value = inl(pr->throttling.address);
  542. /*
  543. * Compute the current throttling state when throttling is enabled
  544. * (bit 4 is on).
  545. */
  546. if (value & 0x10) {
  547. duty_value = value & duty_mask;
  548. duty_value >>= pr->throttling.duty_offset;
  549. if (duty_value)
  550. state = pr->throttling.state_count - duty_value;
  551. }
  552. pr->throttling.state = state;
  553. local_irq_enable();
  554. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  555. "Throttling state is T%d (%d%% throttling applied)\n",
  556. state, pr->throttling.states[state].performance));
  557. return 0;
  558. }
  559. #ifdef CONFIG_X86
  560. static int acpi_throttling_rdmsr(struct acpi_processor *pr,
  561. acpi_integer * value)
  562. {
  563. struct cpuinfo_x86 *c;
  564. u64 msr_high, msr_low;
  565. unsigned int cpu;
  566. u64 msr = 0;
  567. int ret = -1;
  568. cpu = pr->id;
  569. c = &cpu_data(cpu);
  570. if ((c->x86_vendor != X86_VENDOR_INTEL) ||
  571. !cpu_has(c, X86_FEATURE_ACPI)) {
  572. printk(KERN_ERR PREFIX
  573. "HARDWARE addr space,NOT supported yet\n");
  574. } else {
  575. msr_low = 0;
  576. msr_high = 0;
  577. rdmsr_safe(MSR_IA32_THERM_CONTROL,
  578. (u32 *)&msr_low , (u32 *) &msr_high);
  579. msr = (msr_high << 32) | msr_low;
  580. *value = (acpi_integer) msr;
  581. ret = 0;
  582. }
  583. return ret;
  584. }
  585. static int acpi_throttling_wrmsr(struct acpi_processor *pr, acpi_integer value)
  586. {
  587. struct cpuinfo_x86 *c;
  588. unsigned int cpu;
  589. int ret = -1;
  590. u64 msr;
  591. cpu = pr->id;
  592. c = &cpu_data(cpu);
  593. if ((c->x86_vendor != X86_VENDOR_INTEL) ||
  594. !cpu_has(c, X86_FEATURE_ACPI)) {
  595. printk(KERN_ERR PREFIX
  596. "HARDWARE addr space,NOT supported yet\n");
  597. } else {
  598. msr = value;
  599. wrmsr_safe(MSR_IA32_THERM_CONTROL,
  600. msr & 0xffffffff, msr >> 32);
  601. ret = 0;
  602. }
  603. return ret;
  604. }
  605. #else
  606. static int acpi_throttling_rdmsr(struct acpi_processor *pr,
  607. acpi_integer * value)
  608. {
  609. printk(KERN_ERR PREFIX
  610. "HARDWARE addr space,NOT supported yet\n");
  611. return -1;
  612. }
  613. static int acpi_throttling_wrmsr(struct acpi_processor *pr, acpi_integer value)
  614. {
  615. printk(KERN_ERR PREFIX
  616. "HARDWARE addr space,NOT supported yet\n");
  617. return -1;
  618. }
  619. #endif
  620. static int acpi_read_throttling_status(struct acpi_processor *pr,
  621. acpi_integer *value)
  622. {
  623. u32 bit_width, bit_offset;
  624. u64 ptc_value;
  625. u64 ptc_mask;
  626. struct acpi_processor_throttling *throttling;
  627. int ret = -1;
  628. throttling = &pr->throttling;
  629. switch (throttling->status_register.space_id) {
  630. case ACPI_ADR_SPACE_SYSTEM_IO:
  631. ptc_value = 0;
  632. bit_width = throttling->status_register.bit_width;
  633. bit_offset = throttling->status_register.bit_offset;
  634. acpi_os_read_port((acpi_io_address) throttling->status_register.
  635. address, (u32 *) &ptc_value,
  636. (u32) (bit_width + bit_offset));
  637. ptc_mask = (1 << bit_width) - 1;
  638. *value = (acpi_integer) ((ptc_value >> bit_offset) & ptc_mask);
  639. ret = 0;
  640. break;
  641. case ACPI_ADR_SPACE_FIXED_HARDWARE:
  642. ret = acpi_throttling_rdmsr(pr, value);
  643. break;
  644. default:
  645. printk(KERN_ERR PREFIX "Unknown addr space %d\n",
  646. (u32) (throttling->status_register.space_id));
  647. }
  648. return ret;
  649. }
  650. static int acpi_write_throttling_state(struct acpi_processor *pr,
  651. acpi_integer value)
  652. {
  653. u32 bit_width, bit_offset;
  654. u64 ptc_value;
  655. u64 ptc_mask;
  656. struct acpi_processor_throttling *throttling;
  657. int ret = -1;
  658. throttling = &pr->throttling;
  659. switch (throttling->control_register.space_id) {
  660. case ACPI_ADR_SPACE_SYSTEM_IO:
  661. bit_width = throttling->control_register.bit_width;
  662. bit_offset = throttling->control_register.bit_offset;
  663. ptc_mask = (1 << bit_width) - 1;
  664. ptc_value = value & ptc_mask;
  665. acpi_os_write_port((acpi_io_address) throttling->
  666. control_register.address,
  667. (u32) (ptc_value << bit_offset),
  668. (u32) (bit_width + bit_offset));
  669. ret = 0;
  670. break;
  671. case ACPI_ADR_SPACE_FIXED_HARDWARE:
  672. ret = acpi_throttling_wrmsr(pr, value);
  673. break;
  674. default:
  675. printk(KERN_ERR PREFIX "Unknown addr space %d\n",
  676. (u32) (throttling->control_register.space_id));
  677. }
  678. return ret;
  679. }
  680. static int acpi_get_throttling_state(struct acpi_processor *pr,
  681. acpi_integer value)
  682. {
  683. int i;
  684. for (i = 0; i < pr->throttling.state_count; i++) {
  685. struct acpi_processor_tx_tss *tx =
  686. (struct acpi_processor_tx_tss *)&(pr->throttling.
  687. states_tss[i]);
  688. if (tx->control == value)
  689. return i;
  690. }
  691. return -1;
  692. }
  693. static int acpi_get_throttling_value(struct acpi_processor *pr,
  694. int state, acpi_integer *value)
  695. {
  696. int ret = -1;
  697. if (state >= 0 && state <= pr->throttling.state_count) {
  698. struct acpi_processor_tx_tss *tx =
  699. (struct acpi_processor_tx_tss *)&(pr->throttling.
  700. states_tss[state]);
  701. *value = tx->control;
  702. ret = 0;
  703. }
  704. return ret;
  705. }
  706. static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr)
  707. {
  708. int state = 0;
  709. int ret;
  710. acpi_integer value;
  711. if (!pr)
  712. return -EINVAL;
  713. if (!pr->flags.throttling)
  714. return -ENODEV;
  715. pr->throttling.state = 0;
  716. value = 0;
  717. ret = acpi_read_throttling_status(pr, &value);
  718. if (ret >= 0) {
  719. state = acpi_get_throttling_state(pr, value);
  720. if (state == -1) {
  721. ACPI_WARNING((AE_INFO,
  722. "Invalid throttling state, reset"));
  723. state = 0;
  724. ret = acpi_processor_set_throttling(pr, state);
  725. if (ret)
  726. return ret;
  727. }
  728. pr->throttling.state = state;
  729. }
  730. return 0;
  731. }
  732. static int acpi_processor_get_throttling(struct acpi_processor *pr)
  733. {
  734. cpumask_var_t saved_mask;
  735. int ret;
  736. if (!pr)
  737. return -EINVAL;
  738. if (!pr->flags.throttling)
  739. return -ENODEV;
  740. if (!alloc_cpumask_var(&saved_mask, GFP_KERNEL))
  741. return -ENOMEM;
  742. /*
  743. * Migrate task to the cpu pointed by pr.
  744. */
  745. cpumask_copy(saved_mask, &current->cpus_allowed);
  746. /* FIXME: use work_on_cpu() */
  747. set_cpus_allowed_ptr(current, cpumask_of(pr->id));
  748. ret = pr->throttling.acpi_processor_get_throttling(pr);
  749. /* restore the previous state */
  750. set_cpus_allowed_ptr(current, saved_mask);
  751. free_cpumask_var(saved_mask);
  752. return ret;
  753. }
  754. static int acpi_processor_get_fadt_info(struct acpi_processor *pr)
  755. {
  756. int i, step;
  757. if (!pr->throttling.address) {
  758. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n"));
  759. return -EINVAL;
  760. } else if (!pr->throttling.duty_width) {
  761. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling states\n"));
  762. return -EINVAL;
  763. }
  764. /* TBD: Support duty_cycle values that span bit 4. */
  765. else if ((pr->throttling.duty_offset + pr->throttling.duty_width) > 4) {
  766. printk(KERN_WARNING PREFIX "duty_cycle spans bit 4\n");
  767. return -EINVAL;
  768. }
  769. pr->throttling.state_count = 1 << acpi_gbl_FADT.duty_width;
  770. /*
  771. * Compute state values. Note that throttling displays a linear power
  772. * performance relationship (at 50% performance the CPU will consume
  773. * 50% power). Values are in 1/10th of a percent to preserve accuracy.
  774. */
  775. step = (1000 / pr->throttling.state_count);
  776. for (i = 0; i < pr->throttling.state_count; i++) {
  777. pr->throttling.states[i].performance = 1000 - step * i;
  778. pr->throttling.states[i].power = 1000 - step * i;
  779. }
  780. return 0;
  781. }
  782. static int acpi_processor_set_throttling_fadt(struct acpi_processor *pr,
  783. int state)
  784. {
  785. u32 value = 0;
  786. u32 duty_mask = 0;
  787. u32 duty_value = 0;
  788. if (!pr)
  789. return -EINVAL;
  790. if ((state < 0) || (state > (pr->throttling.state_count - 1)))
  791. return -EINVAL;
  792. if (!pr->flags.throttling)
  793. return -ENODEV;
  794. if (state == pr->throttling.state)
  795. return 0;
  796. if (state < pr->throttling_platform_limit)
  797. return -EPERM;
  798. /*
  799. * Calculate the duty_value and duty_mask.
  800. */
  801. if (state) {
  802. duty_value = pr->throttling.state_count - state;
  803. duty_value <<= pr->throttling.duty_offset;
  804. /* Used to clear all duty_value bits */
  805. duty_mask = pr->throttling.state_count - 1;
  806. duty_mask <<= acpi_gbl_FADT.duty_offset;
  807. duty_mask = ~duty_mask;
  808. }
  809. local_irq_disable();
  810. /*
  811. * Disable throttling by writing a 0 to bit 4. Note that we must
  812. * turn it off before you can change the duty_value.
  813. */
  814. value = inl(pr->throttling.address);
  815. if (value & 0x10) {
  816. value &= 0xFFFFFFEF;
  817. outl(value, pr->throttling.address);
  818. }
  819. /*
  820. * Write the new duty_value and then enable throttling. Note
  821. * that a state value of 0 leaves throttling disabled.
  822. */
  823. if (state) {
  824. value &= duty_mask;
  825. value |= duty_value;
  826. outl(value, pr->throttling.address);
  827. value |= 0x00000010;
  828. outl(value, pr->throttling.address);
  829. }
  830. pr->throttling.state = state;
  831. local_irq_enable();
  832. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  833. "Throttling state set to T%d (%d%%)\n", state,
  834. (pr->throttling.states[state].performance ? pr->
  835. throttling.states[state].performance / 10 : 0)));
  836. return 0;
  837. }
  838. static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr,
  839. int state)
  840. {
  841. int ret;
  842. acpi_integer value;
  843. if (!pr)
  844. return -EINVAL;
  845. if ((state < 0) || (state > (pr->throttling.state_count - 1)))
  846. return -EINVAL;
  847. if (!pr->flags.throttling)
  848. return -ENODEV;
  849. if (state == pr->throttling.state)
  850. return 0;
  851. if (state < pr->throttling_platform_limit)
  852. return -EPERM;
  853. value = 0;
  854. ret = acpi_get_throttling_value(pr, state, &value);
  855. if (ret >= 0) {
  856. acpi_write_throttling_state(pr, value);
  857. pr->throttling.state = state;
  858. }
  859. return 0;
  860. }
  861. int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
  862. {
  863. cpumask_var_t saved_mask;
  864. int ret = 0;
  865. unsigned int i;
  866. struct acpi_processor *match_pr;
  867. struct acpi_processor_throttling *p_throttling;
  868. struct throttling_tstate t_state;
  869. cpumask_var_t online_throttling_cpus;
  870. if (!pr)
  871. return -EINVAL;
  872. if (!pr->flags.throttling)
  873. return -ENODEV;
  874. if ((state < 0) || (state > (pr->throttling.state_count - 1)))
  875. return -EINVAL;
  876. if (!alloc_cpumask_var(&saved_mask, GFP_KERNEL))
  877. return -ENOMEM;
  878. if (!alloc_cpumask_var(&online_throttling_cpus, GFP_KERNEL)) {
  879. free_cpumask_var(saved_mask);
  880. return -ENOMEM;
  881. }
  882. cpumask_copy(saved_mask, &current->cpus_allowed);
  883. t_state.target_state = state;
  884. p_throttling = &(pr->throttling);
  885. cpumask_and(online_throttling_cpus, cpu_online_mask,
  886. p_throttling->shared_cpu_map);
  887. /*
  888. * The throttling notifier will be called for every
  889. * affected cpu in order to get one proper T-state.
  890. * The notifier event is THROTTLING_PRECHANGE.
  891. */
  892. for_each_cpu(i, online_throttling_cpus) {
  893. t_state.cpu = i;
  894. acpi_processor_throttling_notifier(THROTTLING_PRECHANGE,
  895. &t_state);
  896. }
  897. /*
  898. * The function of acpi_processor_set_throttling will be called
  899. * to switch T-state. If the coordination type is SW_ALL or HW_ALL,
  900. * it is necessary to call it for every affected cpu. Otherwise
  901. * it can be called only for the cpu pointed by pr.
  902. */
  903. if (p_throttling->shared_type == DOMAIN_COORD_TYPE_SW_ANY) {
  904. /* FIXME: use work_on_cpu() */
  905. set_cpus_allowed_ptr(current, cpumask_of(pr->id));
  906. ret = p_throttling->acpi_processor_set_throttling(pr,
  907. t_state.target_state);
  908. } else {
  909. /*
  910. * When the T-state coordination is SW_ALL or HW_ALL,
  911. * it is necessary to set T-state for every affected
  912. * cpus.
  913. */
  914. for_each_cpu(i, online_throttling_cpus) {
  915. match_pr = per_cpu(processors, i);
  916. /*
  917. * If the pointer is invalid, we will report the
  918. * error message and continue.
  919. */
  920. if (!match_pr) {
  921. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  922. "Invalid Pointer for CPU %d\n", i));
  923. continue;
  924. }
  925. /*
  926. * If the throttling control is unsupported on CPU i,
  927. * we will report the error message and continue.
  928. */
  929. if (!match_pr->flags.throttling) {
  930. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  931. "Throttling Controll is unsupported "
  932. "on CPU %d\n", i));
  933. continue;
  934. }
  935. t_state.cpu = i;
  936. /* FIXME: use work_on_cpu() */
  937. set_cpus_allowed_ptr(current, cpumask_of(i));
  938. ret = match_pr->throttling.
  939. acpi_processor_set_throttling(
  940. match_pr, t_state.target_state);
  941. }
  942. }
  943. /*
  944. * After the set_throttling is called, the
  945. * throttling notifier is called for every
  946. * affected cpu to update the T-states.
  947. * The notifier event is THROTTLING_POSTCHANGE
  948. */
  949. for_each_cpu(i, online_throttling_cpus) {
  950. t_state.cpu = i;
  951. acpi_processor_throttling_notifier(THROTTLING_POSTCHANGE,
  952. &t_state);
  953. }
  954. /* restore the previous state */
  955. /* FIXME: use work_on_cpu() */
  956. set_cpus_allowed_ptr(current, saved_mask);
  957. free_cpumask_var(online_throttling_cpus);
  958. free_cpumask_var(saved_mask);
  959. return ret;
  960. }
  961. int acpi_processor_get_throttling_info(struct acpi_processor *pr)
  962. {
  963. int result = 0;
  964. struct acpi_processor_throttling *pthrottling;
  965. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  966. "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n",
  967. pr->throttling.address,
  968. pr->throttling.duty_offset,
  969. pr->throttling.duty_width));
  970. if (!pr)
  971. return -EINVAL;
  972. /*
  973. * Evaluate _PTC, _TSS and _TPC
  974. * They must all be present or none of them can be used.
  975. */
  976. if (acpi_processor_get_throttling_control(pr) ||
  977. acpi_processor_get_throttling_states(pr) ||
  978. acpi_processor_get_platform_limit(pr))
  979. {
  980. pr->throttling.acpi_processor_get_throttling =
  981. &acpi_processor_get_throttling_fadt;
  982. pr->throttling.acpi_processor_set_throttling =
  983. &acpi_processor_set_throttling_fadt;
  984. if (acpi_processor_get_fadt_info(pr))
  985. return 0;
  986. } else {
  987. pr->throttling.acpi_processor_get_throttling =
  988. &acpi_processor_get_throttling_ptc;
  989. pr->throttling.acpi_processor_set_throttling =
  990. &acpi_processor_set_throttling_ptc;
  991. }
  992. /*
  993. * If TSD package for one CPU can't be parsed successfully, it means
  994. * that this CPU will have no coordination with other CPUs.
  995. */
  996. if (acpi_processor_get_tsd(pr)) {
  997. pthrottling = &pr->throttling;
  998. pthrottling->tsd_valid_flag = 0;
  999. cpumask_set_cpu(pr->id, pthrottling->shared_cpu_map);
  1000. pthrottling->shared_type = DOMAIN_COORD_TYPE_SW_ALL;
  1001. }
  1002. /*
  1003. * PIIX4 Errata: We don't support throttling on the original PIIX4.
  1004. * This shouldn't be an issue as few (if any) mobile systems ever
  1005. * used this part.
  1006. */
  1007. if (errata.piix4.throttle) {
  1008. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1009. "Throttling not supported on PIIX4 A- or B-step\n"));
  1010. return 0;
  1011. }
  1012. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
  1013. pr->throttling.state_count));
  1014. pr->flags.throttling = 1;
  1015. /*
  1016. * Disable throttling (if enabled). We'll let subsequent policy (e.g.
  1017. * thermal) decide to lower performance if it so chooses, but for now
  1018. * we'll crank up the speed.
  1019. */
  1020. result = acpi_processor_get_throttling(pr);
  1021. if (result)
  1022. goto end;
  1023. if (pr->throttling.state) {
  1024. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1025. "Disabling throttling (was T%d)\n",
  1026. pr->throttling.state));
  1027. result = acpi_processor_set_throttling(pr, 0);
  1028. if (result)
  1029. goto end;
  1030. }
  1031. end:
  1032. if (result)
  1033. pr->flags.throttling = 0;
  1034. return result;
  1035. }
  1036. /* proc interface */
  1037. static int acpi_processor_throttling_seq_show(struct seq_file *seq,
  1038. void *offset)
  1039. {
  1040. struct acpi_processor *pr = seq->private;
  1041. int i = 0;
  1042. int result = 0;
  1043. if (!pr)
  1044. goto end;
  1045. if (!(pr->throttling.state_count > 0)) {
  1046. seq_puts(seq, "<not supported>\n");
  1047. goto end;
  1048. }
  1049. result = acpi_processor_get_throttling(pr);
  1050. if (result) {
  1051. seq_puts(seq,
  1052. "Could not determine current throttling state.\n");
  1053. goto end;
  1054. }
  1055. seq_printf(seq, "state count: %d\n"
  1056. "active state: T%d\n"
  1057. "state available: T%d to T%d\n",
  1058. pr->throttling.state_count, pr->throttling.state,
  1059. pr->throttling_platform_limit,
  1060. pr->throttling.state_count - 1);
  1061. seq_puts(seq, "states:\n");
  1062. if (pr->throttling.acpi_processor_get_throttling ==
  1063. acpi_processor_get_throttling_fadt) {
  1064. for (i = 0; i < pr->throttling.state_count; i++)
  1065. seq_printf(seq, " %cT%d: %02d%%\n",
  1066. (i == pr->throttling.state ? '*' : ' '), i,
  1067. (pr->throttling.states[i].performance ? pr->
  1068. throttling.states[i].performance / 10 : 0));
  1069. } else {
  1070. for (i = 0; i < pr->throttling.state_count; i++)
  1071. seq_printf(seq, " %cT%d: %02d%%\n",
  1072. (i == pr->throttling.state ? '*' : ' '), i,
  1073. (int)pr->throttling.states_tss[i].
  1074. freqpercentage);
  1075. }
  1076. end:
  1077. return 0;
  1078. }
  1079. static int acpi_processor_throttling_open_fs(struct inode *inode,
  1080. struct file *file)
  1081. {
  1082. return single_open(file, acpi_processor_throttling_seq_show,
  1083. PDE(inode)->data);
  1084. }
  1085. static ssize_t acpi_processor_write_throttling(struct file *file,
  1086. const char __user * buffer,
  1087. size_t count, loff_t * data)
  1088. {
  1089. int result = 0;
  1090. struct seq_file *m = file->private_data;
  1091. struct acpi_processor *pr = m->private;
  1092. char state_string[5] = "";
  1093. char *charp = NULL;
  1094. size_t state_val = 0;
  1095. char tmpbuf[5] = "";
  1096. if (!pr || (count > sizeof(state_string) - 1))
  1097. return -EINVAL;
  1098. if (copy_from_user(state_string, buffer, count))
  1099. return -EFAULT;
  1100. state_string[count] = '\0';
  1101. if ((count > 0) && (state_string[count-1] == '\n'))
  1102. state_string[count-1] = '\0';
  1103. charp = state_string;
  1104. if ((state_string[0] == 't') || (state_string[0] == 'T'))
  1105. charp++;
  1106. state_val = simple_strtoul(charp, NULL, 0);
  1107. if (state_val >= pr->throttling.state_count)
  1108. return -EINVAL;
  1109. snprintf(tmpbuf, 5, "%zu", state_val);
  1110. if (strcmp(tmpbuf, charp) != 0)
  1111. return -EINVAL;
  1112. result = acpi_processor_set_throttling(pr, state_val);
  1113. if (result)
  1114. return result;
  1115. return count;
  1116. }
  1117. const struct file_operations acpi_processor_throttling_fops = {
  1118. .owner = THIS_MODULE,
  1119. .open = acpi_processor_throttling_open_fs,
  1120. .read = seq_read,
  1121. .write = acpi_processor_write_throttling,
  1122. .llseek = seq_lseek,
  1123. .release = single_release,
  1124. };