drivers/misc/sgi-gru/grukservices.c
Source file repositories/reference/linux-study-clean/drivers/misc/sgi-gru/grukservices.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/sgi-gru/grukservices.c- Extension
.c- Size
- 29449 bytes
- Lines
- 1158
- Domain
- Driver Families
- Bucket
- drivers/misc
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/errno.hlinux/slab.hlinux/mm.hlinux/spinlock.hlinux/device.hlinux/miscdevice.hlinux/proc_fs.hlinux/interrupt.hlinux/sync_core.hlinux/uaccess.hlinux/delay.hlinux/export.hasm/io_apic.hgru.hgrulib.hgrutables.hgrukservices.hgru_instructions.hasm/uv/uv_hub.h
Detected Declarations
struct message_queuestruct message_headerfunction gru_load_kernel_contextfunction gru_free_kernel_contextsfunction gru_unlock_kernel_contextfunction gru_get_cpu_resourcesfunction gru_free_cpu_resourcesfunction gru_reserve_async_resourcesfunction gru_release_async_resourcesfunction gru_wait_async_cbrfunction gru_lock_async_resourcefunction gru_unlock_async_resourcefunction gru_get_cb_exception_detailfunction calledfunction gru_wait_idle_or_exceptionfunction gru_retry_exceptionfunction gru_check_status_procfunction gru_wait_procfunction gru_abortfunction gru_wait_abort_procfunction get_present2function restore_present2function gru_create_message_queuefunction send_noop_messagefunction send_message_queue_fullfunction send_message_put_nackedfunction send_message_failurefunction sizefunction gru_free_messagefunction gru_read_gpafunction gru_copy_gpafunction quicktest0function quicktest1function quicktest2function quicktest3function gru_ktestfunction gru_kservices_initfunction gru_kservices_exitexport gru_create_message_queueexport gru_send_message_gpaexport gru_free_messageexport gru_get_next_messageexport gru_read_gpaexport gru_copy_gpa
Annotated Snippet
struct message_queue {
union gru_mesqhead head __gru_cacheline_aligned__; /* CL 0 */
int qlines; /* DW 1 */
long hstatus[2];
void *next __gru_cacheline_aligned__;/* CL 1 */
void *limit;
void *start;
void *start2;
char data ____cacheline_aligned; /* CL 2 */
};
/* First word in every message - used by mesq interface */
struct message_header {
char present;
char present2;
char lines;
char fill;
};
#define HSTATUS(mq, h) ((mq) + offsetof(struct message_queue, hstatus[h]))
/*
* Reload the blade's kernel context into a GRU chiplet. Called holding
* the bs_kgts_sema for READ. Will steal user contexts if necessary.
*/
static void gru_load_kernel_context(struct gru_blade_state *bs, int blade_id)
{
struct gru_state *gru;
struct gru_thread_state *kgts;
void *vaddr;
int ctxnum, ncpus;
up_read(&bs->bs_kgts_sema);
down_write(&bs->bs_kgts_sema);
if (!bs->bs_kgts) {
do {
bs->bs_kgts = gru_alloc_gts(NULL, 0, 0, 0, 0, 0);
if (!IS_ERR(bs->bs_kgts))
break;
msleep(1);
} while (true);
bs->bs_kgts->ts_user_blade_id = blade_id;
}
kgts = bs->bs_kgts;
if (!kgts->ts_gru) {
STAT(load_kernel_context);
ncpus = uv_blade_nr_possible_cpus(blade_id);
kgts->ts_cbr_au_count = GRU_CB_COUNT_TO_AU(
GRU_NUM_KERNEL_CBR * ncpus + bs->bs_async_cbrs);
kgts->ts_dsr_au_count = GRU_DS_BYTES_TO_AU(
GRU_NUM_KERNEL_DSR_BYTES * ncpus +
bs->bs_async_dsr_bytes);
while (!gru_assign_gru_context(kgts)) {
msleep(1);
gru_steal_context(kgts);
}
gru_load_context(kgts);
gru = bs->bs_kgts->ts_gru;
vaddr = gru->gs_gru_base_vaddr;
ctxnum = kgts->ts_ctxnum;
bs->kernel_cb = get_gseg_base_address_cb(vaddr, ctxnum, 0);
bs->kernel_dsr = get_gseg_base_address_ds(vaddr, ctxnum, 0);
}
downgrade_write(&bs->bs_kgts_sema);
}
/*
* Free all kernel contexts that are not currently in use.
* Returns 0 if all freed, else number of inuse context.
*/
static int gru_free_kernel_contexts(void)
{
struct gru_blade_state *bs;
struct gru_thread_state *kgts;
int bid, ret = 0;
for (bid = 0; bid < GRU_MAX_BLADES; bid++) {
bs = gru_base[bid];
if (!bs)
continue;
/* Ignore busy contexts. Don't want to block here. */
if (down_write_trylock(&bs->bs_kgts_sema)) {
kgts = bs->bs_kgts;
if (kgts && kgts->ts_gru)
gru_unload_context(kgts, 0);
bs->bs_kgts = NULL;
up_write(&bs->bs_kgts_sema);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/slab.h`, `linux/mm.h`, `linux/spinlock.h`, `linux/device.h`, `linux/miscdevice.h`, `linux/proc_fs.h`.
- Detected declarations: `struct message_queue`, `struct message_header`, `function gru_load_kernel_context`, `function gru_free_kernel_contexts`, `function gru_unlock_kernel_context`, `function gru_get_cpu_resources`, `function gru_free_cpu_resources`, `function gru_reserve_async_resources`, `function gru_release_async_resources`, `function gru_wait_async_cbr`.
- Atlas domain: Driver Families / drivers/misc.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.