File: idle.c

package info (click to toggle)
syslinux 3%3A6.03%2Bdfsg-14.1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 41,508 kB
  • sloc: ansic: 358,767; asm: 9,608; pascal: 4,809; perl: 3,894; makefile: 2,486; sh: 315; python: 266; xml: 39
file content (51 lines) | stat: -rw-r--r-- 1,376 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* ----------------------------------------------------------------------- *
 *   
 *   Copyright 2008 H. Peter Anvin - All Rights Reserved
 *   Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 *   Boston MA 02110-1301, USA; either version 2 of the License, or
 *   (at your option) any later version; incorporated herein by reference.
 *
 * ----------------------------------------------------------------------- */

/*
 * idle.c:
 *
 * This function provided protected-mode access to the idle handling.
 * It needs to be carefully coordinated with idle.inc, which provides
 * idle services to real-mode code.
 */

#include "core.h"
#include <sys/cpu.h>

#define TICKS_TO_IDLE	4	/* Also in idle.inc */

static jiffies_t _IdleTimer;
__export uint16_t NoHalt = 0;

int (*idle_hook_func)(void);

void reset_idle(void)
{
    _IdleTimer = jiffies();
    sti();	/* Guard against BIOS/PXE brokenness... */
}

__export void __idle(void)
{
    if (jiffies() - _IdleTimer < TICKS_TO_IDLE)
	return;

    if (idle_hook_func && idle_hook_func())
	return;			/* Nonzero return = do not idle */

    sti();
    if (NoHalt)
	cpu_relax();
    else
	hlt();
}