iPXE
process.h File Reference

Processes. More...

#include <ipxe/list.h>
#include <ipxe/refcnt.h>
#include <ipxe/tables.h>

Go to the source code of this file.

Data Structures

struct  process
 A process. More...
struct  process_descriptor
 A process descriptor. More...

Macros

#define PROC_STEP(object_type, step)
 Define a process step() method.
#define process_offset(object_type, name)
 Calculate offset of process within containing object.
#define PROC_DESC(object_type, process, _step)
 Define a process descriptor.
#define PROC_DESC_ONCE(object_type, process, _step)
 Define a process descriptor for a process that runs only once.
#define PROC_DESC_PURE(_step)
 Define a process descriptor for a pure process.
#define PROC_INIT(_process, _desc)
 Initialise a static process.
#define PERMANENT_PROCESSES   __table ( struct process, "processes" )
 Permanent process table.
#define __permanent_process   __table_entry ( PERMANENT_PROCESSES, 01 )
 Declare a permanent process.
#define PERMANENT_PROCESS(name, step)
 Define a permanent process.
#define PROC_COL(process)
 Find debugging colourisation for a process.
#define PROC_FMT   "%p %s()"
 printf() format string for PROC_DBG()
#define PROC_DBG(process)
 printf() arguments for representing a process

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
void * process_object (struct process *process)
 Get pointer to object containing process.
void process_add (struct process *process)
 Add process to process list.
void process_del (struct process *process)
 Remove process from process list.
void step (void)
 Single-step a single process.
static void process_init_stopped (struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
 Initialise process without adding to process list.
static void process_init (struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
 Initialise process and add to process list.
static int process_running (struct process *process)
 Check if process is running.

Detailed Description

Processes.

Definition in file process.h.

Macro Definition Documentation

◆ PROC_STEP

#define PROC_STEP ( object_type,
step )
Value:
( ( ( ( typeof ( step ) * ) NULL ) == \
( ( void ( * ) ( object_type *object ) ) NULL ) ) ? \
( void ( * ) ( void *object ) ) step : \
( void ( * ) ( void *object ) ) step )
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition acpi.c:48
void step(void)
Single-step a single process.
Definition process.c:99

Define a process step() method.

Parameters
object_typeImplementing method's expected object type
stepImplementing method
Return values
stepProcess step method

Definition at line 56 of file process.h.

56#define PROC_STEP( object_type, step ) \
57 ( ( ( ( typeof ( step ) * ) NULL ) == \
58 ( ( void ( * ) ( object_type *object ) ) NULL ) ) ? \
59 ( void ( * ) ( void *object ) ) step : \
60 ( void ( * ) ( void *object ) ) step )

◆ process_offset

#define process_offset ( object_type,
name )
Value:
( ( ( ( typeof ( ( ( object_type * ) NULL )->name ) * ) NULL ) \
== ( ( struct process * ) NULL ) ) \
? offsetof ( object_type, name ) \
: offsetof ( object_type, name ) )
const char * name
Definition ath9k_hw.c:1986
#define offsetof(type, field)
Get offset of a field within a structure.
Definition stddef.h:25
A process.
Definition process.h:18

Calculate offset of process within containing object.

Parameters
object_typeContaining object data type
nameProcess name (i.e. field within object data type)
Return values
offsetOffset of process within containing object

Definition at line 69 of file process.h.

69#define process_offset( object_type, name ) \
70 ( ( ( ( typeof ( ( ( object_type * ) NULL )->name ) * ) NULL ) \
71 == ( ( struct process * ) NULL ) ) \
72 ? offsetof ( object_type, name ) \
73 : offsetof ( object_type, name ) )

◆ PROC_DESC

#define PROC_DESC ( object_type,
process,
_step )
Value:
{ \
.name = #_step, \
.offset = process_offset ( object_type, process ), \
.step = PROC_STEP ( object_type, _step ), \
.reschedule = 1, \
}
#define PROC_STEP(object_type, step)
Define a process step() method.
Definition process.h:56
#define process_offset(object_type, name)
Calculate offset of process within containing object.
Definition process.h:69

Define a process descriptor.

Parameters
object_typeContaining object data type
processProcess name (i.e. field within object data type)
stepProcess' step() method
Return values
descObject interface descriptor

Definition at line 83 of file process.h.

83#define PROC_DESC( object_type, process, _step ) { \
84 .name = #_step, \
85 .offset = process_offset ( object_type, process ), \
86 .step = PROC_STEP ( object_type, _step ), \
87 .reschedule = 1, \
88 }

◆ PROC_DESC_ONCE

#define PROC_DESC_ONCE ( object_type,
process,
_step )
Value:
{ \
.name = #_step, \
.offset = process_offset ( object_type, process ), \
.step = PROC_STEP ( object_type, _step ), \
.reschedule = 0, \
}

Define a process descriptor for a process that runs only once.

Parameters
object_typeContaining object data type
processProcess name (i.e. field within object data type)
stepProcess' step() method
Return values
descObject interface descriptor

Definition at line 98 of file process.h.

98#define PROC_DESC_ONCE( object_type, process, _step ) { \
99 .name = #_step, \
100 .offset = process_offset ( object_type, process ), \
101 .step = PROC_STEP ( object_type, _step ), \
102 .reschedule = 0, \
103 }

◆ PROC_DESC_PURE

#define PROC_DESC_PURE ( _step)
Value:
{ \
.name = #_step, \
.offset = 0, \
.step = PROC_STEP ( struct process, _step ), \
.reschedule = 1, \
}

Define a process descriptor for a pure process.

A pure process is a process that does not have a containing object.

Parameters
stepProcess' step() method
Return values
descObject interface descriptor

Definition at line 113 of file process.h.

113#define PROC_DESC_PURE( _step ) { \
114 .name = #_step, \
115 .offset = 0, \
116 .step = PROC_STEP ( struct process, _step ), \
117 .reschedule = 1, \
118 }

◆ PROC_INIT

#define PROC_INIT ( _process,
_desc )
Value:
{ \
.list = LIST_HEAD_INIT ( (_process).list ), \
.desc = (_desc), \
.refcnt = NULL, \
}
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition list.h:31
A reference counter.
Definition refcnt.h:27

Initialise a static process.

Parameters
processProcess
descProcess descriptor

Definition at line 132 of file process.h.

132#define PROC_INIT( _process, _desc ) { \
133 .list = LIST_HEAD_INIT ( (_process).list ), \
134 .desc = (_desc), \
135 .refcnt = NULL, \
136 }

◆ PERMANENT_PROCESSES

#define PERMANENT_PROCESSES   __table ( struct process, "processes" )

Permanent process table.

Definition at line 181 of file process.h.

Referenced by init_processes().

◆ __permanent_process

#define __permanent_process   __table_entry ( PERMANENT_PROCESSES, 01 )

Declare a permanent process.

Permanent processes will be automatically added to the process list at initialisation time.

Definition at line 189 of file process.h.

◆ PERMANENT_PROCESS

#define PERMANENT_PROCESS ( name,
step )
Value:
static struct process_descriptor name ## _desc = PROC_DESC_PURE ( step ); \
#define __permanent_process
Declare a permanent process.
Definition process.h:189
#define PROC_DESC_PURE(_step)
Define a process descriptor for a pure process.
Definition process.h:113
#define PROC_INIT(_process, _desc)
Initialise a static process.
Definition process.h:132
A process descriptor.
Definition process.h:32

Define a permanent process.

Definition at line 194 of file process.h.

194#define PERMANENT_PROCESS( name, step ) \
195static struct process_descriptor name ## _desc = PROC_DESC_PURE ( step ); \
196struct process name __permanent_process = PROC_INIT ( name, & name ## _desc );

◆ PROC_COL

#define PROC_COL ( process)
Value:
void * process_object(struct process *process)
Get pointer to object containing process.
Definition process.c:48

Find debugging colourisation for a process.

Parameters
processProcess
Return values
colDebugging colourisation

Use as the first argument to DBGC() or equivalent macro.

Definition at line 206 of file process.h.

Referenced by process_add(), process_del(), and step().

◆ PROC_FMT

#define PROC_FMT   "%p %s()"

printf() format string for PROC_DBG()

Definition at line 209 of file process.h.

Referenced by process_add(), process_del(), and step().

◆ PROC_DBG

#define PROC_DBG ( process)
Value:
struct ena_llq_option desc
Descriptor counts.
Definition ena.h:9

printf() arguments for representing a process

Parameters
processProcess
Return values
argsprintf() argument list corresponding to PROC_FMT

Definition at line 217 of file process.h.

Referenced by process_add(), process_del(), and step().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ process_object()

void * process_object ( struct process * process)
extern

Get pointer to object containing process.

Parameters
processProcess
Return values
objectContaining object

Definition at line 48 of file process.c.

48 {
49 return ( ( ( void * ) process ) - process->desc->offset );
50}
size_t offset
Offset of process within containing object.
Definition process.h:36
struct process_descriptor * desc
Process descriptor.
Definition process.h:22

References process::desc, and process_descriptor::offset.

Referenced by step().

◆ process_add()

void process_add ( struct process * process)
extern

Add process to process list.

Parameters
processProcess

It is safe to call process_add() multiple times; further calls will have no effect.

Definition at line 60 of file process.c.

60 {
61 if ( ! process_running ( process ) ) {
62 DBGC ( PROC_COL ( process ), "PROCESS " PROC_FMT
63 " starting\n", PROC_DBG ( process ) );
65 list_add_tail ( &process->list, &run_queue );
66 } else {
67 DBGC ( PROC_COL ( process ), "PROCESS " PROC_FMT
68 " already started\n", PROC_DBG ( process ) );
69 }
70}
#define DBGC(...)
Definition compiler.h:505
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition list.h:94
#define PROC_DBG(process)
printf() arguments for representing a process
Definition process.h:217
#define PROC_COL(process)
Find debugging colourisation for a process.
Definition process.h:206
static int process_running(struct process *process)
Check if process is running.
Definition process.h:176
#define PROC_FMT
printf() format string for PROC_DBG()
Definition process.h:209
#define ref_get(refcnt)
Get additional reference to object.
Definition refcnt.h:93
struct list_head list
List of processes.
Definition process.h:20
struct refcnt * refcnt
Reference counter.
Definition process.h:28

References DBGC, process::list, list_add_tail, PROC_COL, PROC_DBG, PROC_FMT, process_running(), ref_get, and process::refcnt.

Referenced by efi_local_open(), efi_pxe_udp_schedule_close(), fc_els_request(), fcpcmd_start_send(), gve_restart(), gve_startup(), http_reopen(), hub_complete(), hub_open(), ib_cmrc_close(), imux_probe(), init_processes(), iscsi_tx_resume(), net80211_autoassociate(), peerblk_dequeue(), peerblk_enqueue(), peerblk_retrieval_close(), peerblk_step(), peermux_block_close(), peermux_info_close(), process_init(), sanpath_open(), scsidev_ready(), tcp_close(), tcp_rx(), tls_tx_resume(), usbblk_in_complete(), usbblk_out_complete(), usbblk_start(), validator_xfer_close(), and xcm_reopen().

◆ process_del()

void process_del ( struct process * process)
extern

Remove process from process list.

Parameters
processProcess

It is safe to call process_del() multiple times; further calls will have no effect.

Definition at line 80 of file process.c.

80 {
81 if ( process_running ( process ) ) {
82 DBGC ( PROC_COL ( process ), "PROCESS " PROC_FMT
83 " stopping\n", PROC_DBG ( process ) );
84 list_del ( &process->list );
87 } else {
88 DBGC ( PROC_COL ( process ), "PROCESS " PROC_FMT
89 " already stopped\n", PROC_DBG ( process ) );
90 }
91}
#define list_del(list)
Delete an entry from a list.
Definition list.h:120
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition list.h:46
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107

References DBGC, INIT_LIST_HEAD, process::list, list_del, PROC_COL, PROC_DBG, PROC_FMT, process_running(), ref_put, and process::refcnt.

Referenced by efi_local_close(), efi_pxe_udp_close(), efi_pxe_udp_open(), fc_els_close(), fc_ns_query_close(), fcpcmd_stop_send(), gve_close(), http_close(), hub_close(), hub_refill(), hw_finished(), ib_cmrc_shutdown(), imux_shutdown(), iscsi_close(), iscsi_tx_pause(), net80211_netdev_close(), net80211_step_associate(), peerblk_reset(), peermux_close(), peermux_step(), sanpath_close(), scsidev_close(), step(), tcp_close(), tls_close(), usbblk_stop(), validator_finished(), xcm_close(), xcm_destroy(), and xcm_reopen().

◆ step()

void step ( void )
extern

Single-step a single process.

This executes a single step of the first process in the run queue, and moves the process to the end of the run queue.

Definition at line 99 of file process.c.

99 {
100 struct process *process;
101 struct process_descriptor *desc;
102 void *object;
103
104 if ( ( process = list_first_entry ( &run_queue, struct process,
105 list ) ) ) {
106 ref_get ( process->refcnt ); /* Inhibit destruction mid-step */
107 desc = process->desc;
108 object = process_object ( process );
109 if ( desc->reschedule ) {
110 list_del ( &process->list );
111 list_add_tail ( &process->list, &run_queue );
112 } else {
114 }
115 DBGC2 ( PROC_COL ( process ), "PROCESS " PROC_FMT
116 " executing\n", PROC_DBG ( process ) );
117 desc->step ( object );
118 DBGC2 ( PROC_COL ( process ), "PROCESS " PROC_FMT
119 " finished executing\n", PROC_DBG ( process ) );
120 ref_put ( process->refcnt ); /* Allow destruction */
121 }
122}
#define DBGC2(...)
Definition compiler.h:522
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition list.h:334
void process_del(struct process *process)
Remove process from process list.
Definition process.c:80

References DBGC2, desc, process::desc, process::list, list_add_tail, list_del, list_first_entry, PROC_COL, PROC_DBG, PROC_FMT, process_del(), process_object(), ref_get, ref_put, and process::refcnt.

Referenced by ath5k_hw_rf_check_gainf_readback(), ath5k_hw_rf_gainf_corr(), comboot_resolv(), efi_download_poll(), efi_ifr_numeric_op(), efi_pxe_dhcp(), efi_pxe_mtftp(), efi_pxe_udp_read(), gdbmach_set_single_step(), getchar(), getchar_timeout(), int22(), iwlist(), md4_digest(), md5_digest(), monojob_wait(), open(), pxenv_tftp_get_fsize(), pxenv_tftp_open(), pxenv_tftp_read(), pxenv_tftp_read_file(), pxenv_udp_read(), read(), sandev_command(), sandev_describe(), sandev_reopen(), select(), sha1_digest(), sleep_interruptible(), spi_bit_transfer(), tcp_shutdown(), x25519_ladder(), and x25519_step().

◆ process_init_stopped()

void process_init_stopped ( struct process * process,
struct process_descriptor * desc,
struct refcnt * refcnt )
inlinestatic

Initialise process without adding to process list.

Parameters
processProcess
descProcess descriptor
refcntContaining object reference count, or NULL

Definition at line 146 of file process.h.

148 {
150 process->desc = desc;
152}

References desc, process::desc, INIT_LIST_HEAD, process::list, and process::refcnt.

Referenced by add_tls(), alloc_sandev(), efi_local_open(), efi_pxe_install(), fc_els_create(), fcpdev_scsi_command(), gve_probe(), hub_probe(), ib_cmrc_open(), iscsi_open(), net80211_alloc(), peerblk_open(), peermux_filter(), process_init(), tcp_open(), usbblk_probe(), and xcm_create().

◆ process_init()

void process_init ( struct process * process,
struct process_descriptor * desc,
struct refcnt * refcnt )
inlinestatic

Initialise process and add to process list.

Parameters
processProcess
descProcess descriptor
refcntContaining object reference count, or NULL

Definition at line 162 of file process.h.

164 {
167}
static void process_init_stopped(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process without adding to process list.
Definition process.h:146
void process_add(struct process *process)
Add process to process list.
Definition process.c:60

References desc, process_add(), and process_init_stopped().

Referenced by create_validator(), fc_ns_query(), http_open(), hw_open(), imux_probe(), numeric_resolv(), and scsi_open().

◆ process_running()

int process_running ( struct process * process)
inlinestatic

Check if process is running.

Parameters
processProcess
Return values
runningProcess is running

Definition at line 176 of file process.h.

176 {
177 return ( ! list_empty ( &process->list ) );
178}
#define list_empty(list)
Test whether a list is empty.
Definition list.h:137

References process::list, and list_empty.

Referenced by efi_pxe_udp_close(), efi_pxe_udp_open(), fc_els_free(), hub_remove(), imux_shutdown(), imux_step(), process_add(), process_del(), tcp_first_unfinished(), usbblk_start(), and xcm_free().