My Project
Classes | Macros | Typedefs | Enumerations | Functions | Variables
Job Scheduler Internal APIs

Classes

struct  kbasep_atom_req
 
struct  kbasep_js_per_as_data
 
struct  kbasep_js_device_data
 KBase Device Data Job Scheduler sub-structure. More...
 
struct  kbasep_js_kctx_info
 KBase Context Job Scheduling information structure. More...
 
struct  kbasep_js_atom_retained_state
 

Macros

#define KBASE_JS_MAX_JOB_SUBMIT_PER_SLOT_PER_IRQ   2
 Maximum number of jobs that can be submitted to a job slot whilst inside the IRQ handler. More...
 
#define KBASE_JS_IRQ_THROTTLE_TIME_US   20
 the IRQ_THROTTLE time in microseconds More...
 
#define KBASEP_JS_RETRY_SUBMIT_SLOT_INVALID   (-1)
 
#define KBASEP_JS_ATOM_RETAINED_STATE_CORE_REQ_INVALID   BASE_JD_REQ_DEP
 
#define KBASEP_JS_TICK_RESOLUTION_US   1
 The JS timer resolution, in microseconds. More...
 
#define KBASE_JS_ATOM_SCHED_PRIO_INVALID   -1
 
#define KBASE_JS_ATOM_SCHED_PRIO_DEFAULT   KBASE_JS_ATOM_SCHED_PRIO_MED
 

Typedefs

typedef u32 kbase_context_flags
 
typedef void(* kbasep_js_ctx_job_cb) (struct kbase_device *kbdev, struct kbase_jd_atom *katom)
 
typedef u32 kbasep_js_atom_done_code
 

Enumerations

enum  kbasep_js_ctx_attr { KBASEP_JS_CTX_ATTR_COMPUTE, KBASEP_JS_CTX_ATTR_NON_COMPUTE, KBASEP_JS_CTX_ATTR_COMPUTE_ALL_CORES, KBASEP_JS_CTX_ATTR_COUNT }
 Context attributes. More...
 
enum  { KBASE_JS_ATOM_DONE_START_NEW_ATOMS = (1u << 0), KBASE_JS_ATOM_DONE_EVICTED_FROM_NEXT = (1u << 1) }
 
enum  { KBASE_JS_ATOM_SCHED_PRIO_HIGH = 0, KBASE_JS_ATOM_SCHED_PRIO_MED, KBASE_JS_ATOM_SCHED_PRIO_LOW, KBASE_JS_ATOM_SCHED_PRIO_COUNT }
 

Functions

int kbasep_js_devdata_init (struct kbase_device *const kbdev)
 Initialize the Job Scheduler. More...
 
void kbasep_js_devdata_halt (struct kbase_device *kbdev)
 Halt the Job Scheduler. More...
 
void kbasep_js_devdata_term (struct kbase_device *kbdev)
 Terminate the Job Scheduler. More...
 
int kbasep_js_kctx_init (struct kbase_context *const kctx)
 Initialize the Scheduling Component of a struct kbase_context on the Job Scheduler. More...
 
void kbasep_js_kctx_term (struct kbase_context *kctx)
 Terminate the Scheduling Component of a struct kbase_context on the Job Scheduler. More...
 
bool kbasep_js_add_job (struct kbase_context *kctx, struct kbase_jd_atom *atom)
 Add a job chain to the Job Scheduler, and take necessary actions to schedule the context/run the job. More...
 
void kbasep_js_remove_job (struct kbase_device *kbdev, struct kbase_context *kctx, struct kbase_jd_atom *atom)
 Remove a job chain from the Job Scheduler, except for its 'retained state'. More...
 
bool kbasep_js_remove_cancelled_job (struct kbase_device *kbdev, struct kbase_context *kctx, struct kbase_jd_atom *katom)
 Completely remove a job chain from the Job Scheduler, in the case where the job chain was cancelled. More...
 
bool kbasep_js_runpool_retain_ctx (struct kbase_device *kbdev, struct kbase_context *kctx)
 Refcount a context as being busy, preventing it from being scheduled out. More...
 
bool kbasep_js_runpool_retain_ctx_nolock (struct kbase_device *kbdev, struct kbase_context *kctx)
 Refcount a context as being busy, preventing it from being scheduled out. More...
 
struct kbase_contextkbasep_js_runpool_lookup_ctx (struct kbase_device *kbdev, int as_nr)
 Lookup a context in the Run Pool based upon its current address space and ensure that is stays scheduled in. More...
 
struct kbase_contextkbasep_js_runpool_lookup_ctx_nolock (struct kbase_device *kbdev, int as_nr)
 
void kbasep_js_runpool_requeue_or_kill_ctx (struct kbase_device *kbdev, struct kbase_context *kctx, bool has_pm_ref)
 Handling the requeuing/killing of a context that was evicted from the policy queue or runpool. More...
 
void kbasep_js_runpool_release_ctx (struct kbase_device *kbdev, struct kbase_context *kctx)
 Release a refcount of a context being busy, allowing it to be scheduled out. More...
 
void kbasep_js_runpool_release_ctx_and_katom_retained_state (struct kbase_device *kbdev, struct kbase_context *kctx, struct kbasep_js_atom_retained_state *katom_retained_state)
 Variant of kbasep_js_runpool_release_ctx() that handles additional actions from completing an atom. More...
 
void kbasep_js_runpool_release_ctx_nolock (struct kbase_device *kbdev, struct kbase_context *kctx)
 Variant of kbase_js_runpool_release_ctx() that assumes that kbasep_js_device_data::runpool_mutex and kbasep_js_kctx_info::ctx::jsctx_mutex are held by the caller, and does not attempt to schedule new contexts.
 
void kbasep_js_schedule_privileged_ctx (struct kbase_device *kbdev, struct kbase_context *kctx)
 Schedule in a privileged context. More...
 
void kbasep_js_release_privileged_ctx (struct kbase_device *kbdev, struct kbase_context *kctx)
 Release a privileged context, allowing it to be scheduled out. More...
 
void kbase_js_try_run_jobs (struct kbase_device *kbdev)
 Try to submit the next job on each slot. More...
 
void kbasep_js_suspend (struct kbase_device *kbdev)
 Suspend the job scheduler during a Power Management Suspend event. More...
 
void kbasep_js_resume (struct kbase_device *kbdev)
 Resume the Job Scheduler after a Power Management Resume event. More...
 
bool kbase_js_dep_resolved_submit (struct kbase_context *kctx, struct kbase_jd_atom *katom)
 Submit an atom to the job scheduler. More...
 
void jsctx_ll_flush_to_rb (struct kbase_context *kctx, int prio, int js)
 
struct kbase_jd_atomkbase_js_pull (struct kbase_context *kctx, int js)
 Pull an atom from a context in the job scheduler for execution. More...
 
void kbase_js_unpull (struct kbase_context *kctx, struct kbase_jd_atom *katom)
 Return an atom to the job scheduler ringbuffer. More...
 
bool kbase_js_complete_atom_wq (struct kbase_context *kctx, struct kbase_jd_atom *katom)
 Complete an atom from jd_done_worker(), removing it from the job scheduler ringbuffer. More...
 
struct kbase_jd_atomkbase_js_complete_atom (struct kbase_jd_atom *katom, ktime_t *end_timestamp)
 Complete an atom. More...
 
void kbase_js_sched (struct kbase_device *kbdev, int js_mask)
 Submit atoms from all available contexts. More...
 
void kbase_js_zap_context (struct kbase_context *kctx)
 
bool kbase_js_is_atom_valid (struct kbase_device *kbdev, struct kbase_jd_atom *katom)
 Validate an atom. More...
 
void kbase_js_set_timeouts (struct kbase_device *kbdev)
 
void kbasep_js_ctx_attr_set_initial_attrs (struct kbase_device *kbdev, struct kbase_context *kctx)
 
void kbasep_js_ctx_attr_runpool_retain_ctx (struct kbase_device *kbdev, struct kbase_context *kctx)
 
bool kbasep_js_ctx_attr_runpool_release_ctx (struct kbase_device *kbdev, struct kbase_context *kctx)
 
void kbasep_js_ctx_attr_ctx_retain_atom (struct kbase_device *kbdev, struct kbase_context *kctx, struct kbase_jd_atom *katom)
 
bool kbasep_js_ctx_attr_ctx_release_atom (struct kbase_device *kbdev, struct kbase_context *kctx, struct kbasep_js_atom_retained_state *katom_retained_state)
 

Variables

const int kbasep_js_atom_priority_to_relative [BASE_JD_NR_PRIO_LEVELS]
 
const base_jd_prio kbasep_js_relative_priority_to_atom [KBASE_JS_ATOM_SCHED_PRIO_COUNT]
 

Detailed Description

These APIs are Internal to KBase.

Macro Definition Documentation

◆ KBASE_JS_IRQ_THROTTLE_TIME_US

#define KBASE_JS_IRQ_THROTTLE_TIME_US   20

the IRQ_THROTTLE time in microseconds

This will be converted via the GPU's clock frequency into a cycle-count.

Note
we can make an estimate of the GPU's frequency by periodically sampling its CYCLE_COUNT register

◆ KBASE_JS_MAX_JOB_SUBMIT_PER_SLOT_PER_IRQ

#define KBASE_JS_MAX_JOB_SUBMIT_PER_SLOT_PER_IRQ   2

Maximum number of jobs that can be submitted to a job slot whilst inside the IRQ handler.

This is important because GPU NULL jobs can complete whilst the IRQ handler is running. Otherwise, it potentially allows an unlimited number of GPU NULL jobs to be submitted inside the IRQ handler, which increases IRQ latency.

◆ KBASEP_JS_ATOM_RETAINED_STATE_CORE_REQ_INVALID

#define KBASEP_JS_ATOM_RETAINED_STATE_CORE_REQ_INVALID   BASE_JD_REQ_DEP

base_jd_core_req value signifying 'invalid' for a kbase_jd_atom_retained_state.

See also
kbase_atom_retained_state_is_valid()

◆ KBASEP_JS_RETRY_SUBMIT_SLOT_INVALID

#define KBASEP_JS_RETRY_SUBMIT_SLOT_INVALID   (-1)

Value signifying 'no retry on a slot required' for:

◆ KBASEP_JS_TICK_RESOLUTION_US

#define KBASEP_JS_TICK_RESOLUTION_US   1

The JS timer resolution, in microseconds.

Any non-zero difference in time will be at least this size.

Typedef Documentation

◆ kbasep_js_atom_done_code

Combination of KBASE_JS_ATOM_DONE_<...> bits

◆ kbasep_js_ctx_job_cb

typedef void(* kbasep_js_ctx_job_cb) (struct kbase_device *kbdev, struct kbase_jd_atom *katom)

Callback function run on all of a context's jobs registered with the Job Scheduler

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
KBASE_JS_ATOM_DONE_START_NEW_ATOMS 

Bit indicating that new atom should be started because this atom completed

KBASE_JS_ATOM_DONE_EVICTED_FROM_NEXT 

Bit indicating that the atom was evicted from the JS_NEXT registers

◆ kbasep_js_ctx_attr

Context attributes.

Each context attribute can be thought of as a boolean value that caches some state information about either the runpool, or the context:

  • In the case of the runpool, it is a cache of "Do any contexts owned by the runpool have attribute X?"
  • In the case of a context, it is a cache of "Do any atoms owned by the context have attribute X?"

The boolean value of the context attributes often affect scheduling decisions, such as affinities to use and job slots to use.

To accomodate changes of state in the context, each attribute is refcounted in the context, and in the runpool for all running contexts. Specifically:

  • The runpool holds a refcount of how many contexts in the runpool have this attribute.
  • The context holds a refcount of how many atoms have this attribute.
Enumerator
KBASEP_JS_CTX_ATTR_COMPUTE 

Attribute indicating a context that contains Compute jobs. That is, the context has jobs of type BASE_JD_REQ_ONLY_COMPUTE

Note
A context can be both 'Compute' and 'Non Compute' if it contains both types of jobs.
KBASEP_JS_CTX_ATTR_NON_COMPUTE 

Attribute indicating a context that contains Non-Compute jobs. That is, the context has some jobs that are not of type BASE_JD_REQ_ONLY_COMPUTE.

Note
A context can be both 'Compute' and 'Non Compute' if it contains both types of jobs.
KBASEP_JS_CTX_ATTR_COMPUTE_ALL_CORES 

Attribute indicating that a context contains compute-job atoms that aren't restricted to a coherent group, and can run on all cores.

Specifically, this is when the atom's core_req satisfy:

  • (core_req & (BASE_JD_REQ_CS | BASE_JD_REQ_ONLY_COMPUTE | BASE_JD_REQ_T) // uses slot 1 or slot 2
  • && !(core_req & BASE_JD_REQ_COHERENT_GROUP) // not restricted to coherent groups

Such atoms could be blocked from running if one of the coherent groups is being used by another job slot, so tracking this context attribute allows us to prevent such situations.

Note
This doesn't take into account the 1-coregroup case, where all compute atoms would effectively be able to run on 'all cores', but contexts will still not always get marked with this attribute. Instead, it is the caller's responsibility to take into account the number of coregroups when interpreting this attribute.
Whilst Tiler atoms are normally combined with BASE_JD_REQ_COHERENT_GROUP, it is possible to send such atoms without BASE_JD_REQ_COHERENT_GROUP set. This is an unlikely case, but it's easy enough to handle anyway.
KBASEP_JS_CTX_ATTR_COUNT 

Must be the last in the enum

Function Documentation

◆ jsctx_ll_flush_to_rb()

void jsctx_ll_flush_to_rb ( struct kbase_context kctx,
int  prio,
int  js 
)

jsctx_ll_flush_to_rb() - Pushes atoms from the linked list to ringbuffer. : Context Pointer : Priority (specifies the queue together with js). : Job slot (specifies the queue together with prio).

Pushes all possible atoms from the linked list to the ringbuffer. Number of atoms are limited to free space in the ringbuffer and number of available atoms in the linked list.

◆ kbase_js_complete_atom()

struct kbase_jd_atom* kbase_js_complete_atom ( struct kbase_jd_atom katom,
ktime_t *  end_timestamp 
)

Complete an atom.

Most of the work required to complete an atom will be performed by jd_done_worker().

The HW access lock must be held when calling this function.

Parameters
[in]katomPointer to the atom to complete
[in]end_timestampThe time that the atom completed (may be NULL)

Return: Atom that has now been unblocked and can now be run, or NULL if none

◆ kbase_js_complete_atom_wq()

bool kbase_js_complete_atom_wq ( struct kbase_context kctx,
struct kbase_jd_atom katom 
)

Complete an atom from jd_done_worker(), removing it from the job scheduler ringbuffer.

If the atom failed then all dependee atoms marked for failure propagation will also fail.

Parameters
[in]kctxContext pointer
[in]katomPointer to the atom to complete
Returns
true if the context is now idle (no jobs pulled) false otherwise

◆ kbase_js_dep_resolved_submit()

bool kbase_js_dep_resolved_submit ( struct kbase_context kctx,
struct kbase_jd_atom katom 
)

Submit an atom to the job scheduler.

The atom is enqueued on the context's ringbuffer. The caller must have ensured that all dependencies can be represented in the ringbuffer.

Caller must hold jctx->lock

Parameters
[in]kctxContext pointer
[in]atomPointer to the atom to submit
Returns
Whether the context requires to be enqueued.

◆ kbase_js_is_atom_valid()

bool kbase_js_is_atom_valid ( struct kbase_device kbdev,
struct kbase_jd_atom katom 
)

Validate an atom.

This will determine whether the atom can be scheduled onto the GPU. Atoms with invalid combinations of core requirements will be rejected.

Parameters
[in]kbdevDevice pointer
[in]katomAtom to validate
Returns
true if atom is valid false otherwise

◆ kbase_js_pull()

struct kbase_jd_atom* kbase_js_pull ( struct kbase_context kctx,
int  js 
)

Pull an atom from a context in the job scheduler for execution.

The atom will not be removed from the ringbuffer at this stage.

The HW access lock must be held when calling this function.

Parameters
[in]kctxContext to pull from
[in]jsJob slot to pull from
Returns
Pointer to an atom, or NULL if there are no atoms for this slot that can be currently run.

◆ kbase_js_sched()

void kbase_js_sched ( struct kbase_device kbdev,
int  js_mask 
)

Submit atoms from all available contexts.

This will attempt to submit as many jobs as possible to the provided job slots. It will exit when either all job slots are full, or all contexts have been used.

Parameters
[in]kbdevDevice pointer
[in]js_maskMask of job slots to submit to

◆ kbase_js_set_timeouts()

void kbase_js_set_timeouts ( struct kbase_device kbdev)

kbase_js_set_timeouts - update all JS timeouts with user specified data : Device pointer

Timeouts are specified through the 'js_timeouts' sysfs file. If a timeout is set to a positive number then that becomes the new value used, if a timeout is negative then the default is set.

◆ kbase_js_try_run_jobs()

void kbase_js_try_run_jobs ( struct kbase_device kbdev)

Try to submit the next job on each slot.

The following locks may be used:

◆ kbase_js_unpull()

void kbase_js_unpull ( struct kbase_context kctx,
struct kbase_jd_atom katom 
)

Return an atom to the job scheduler ringbuffer.

An atom is 'unpulled' if execution is stopped but intended to be returned to later. The most common reason for this is that the atom has been soft-stopped.

Note that if multiple atoms are to be 'unpulled', they must be returned in the reverse order to which they were originally pulled. It is a programming error to return atoms in any other order.

The HW access lock must be held when calling this function.

Parameters
[in]kctxContext pointer
[in]atomPointer to the atom to unpull

◆ kbase_js_zap_context()

void kbase_js_zap_context ( struct kbase_context kctx)

kbase_jd_zap_context - Attempt to deschedule a context that is being destroyed : Context pointer

This will attempt to remove a context from any internal job scheduler queues and perform any other actions to ensure a context will not be submitted from.

If the context is currently scheduled, then the caller must wait for all pending jobs to complete before taking any further action.

◆ kbasep_js_add_job()

bool kbasep_js_add_job ( struct kbase_context kctx,
struct kbase_jd_atom atom 
)

Add a job chain to the Job Scheduler, and take necessary actions to schedule the context/run the job.

This atomically does the following:

  • Update the numbers of jobs information
  • Add the job to the run pool if necessary (part of init_job)

Once this is done, then an appropriate action is taken:

  • If the ctx is scheduled, it attempts to start the next job (which might be this added job)
  • Otherwise, and if this is the first job on the context, it enqueues it on the Policy Queue

The Policy's Queue can be updated by this in the following ways:

  • In the above case that this is the first job on the context
  • If the context is high priority and the context is not scheduled, then it could cause the Policy to schedule out a low-priority context, allowing this context to be scheduled in.

If the context is already scheduled on the RunPool, then adding a job to it is guarenteed not to update the Policy Queue. And so, the caller is guarenteed to not need to try scheduling a context from the Run Pool - it can safely assert that the result is false.

It is a programming error to have more than U32_MAX jobs in flight at a time.

The following locking conditions are made on the caller:

  • it must not hold kbasep_js_kctx_info::ctx::jsctx_mutex.
  • it must not hold hwaccess_lock (as this will be obtained internally)
  • it must not hold kbasep_js_device_data::runpool_mutex (as this will be obtained internally)
  • it must not hold kbasep_jd_device_data::queue_mutex (again, it's used internally).
Returns
true indicates that the Policy Queue was updated, and so the caller will need to try scheduling a context onto the Run Pool.
false indicates that no updates were made to the Policy Queue, so no further action is required from the caller. This is always returned when the context is currently scheduled.

◆ kbasep_js_ctx_attr_ctx_release_atom()

bool kbasep_js_ctx_attr_ctx_release_atom ( struct kbase_device kbdev,
struct kbase_context kctx,
struct kbasep_js_atom_retained_state katom_retained_state 
)

Release all attributes of an atom, given its retained state.

This occurs after (permanently) removing an atom from a context

Requires:

  • jsctx mutex
  • If the context is scheduled, then runpool_irq spinlock must also be held

This is a no-op when katom_retained_state is invalid.

Returns
true indicates a change in ctx attributes state of the runpool. In this state, the scheduler might be able to submit more jobs than previously, and so the caller should ensure kbasep_js_try_run_next_job_nolock() or similar is called sometime later.
false indicates no change in ctx attributes state of the runpool.

◆ kbasep_js_ctx_attr_ctx_retain_atom()

void kbasep_js_ctx_attr_ctx_retain_atom ( struct kbase_device kbdev,
struct kbase_context kctx,
struct kbase_jd_atom katom 
)

Retain all attributes of an atom

This occurs on adding an atom to a context

Requires:

  • jsctx mutex
  • If the context is scheduled, then runpool_irq spinlock must also be held

◆ kbasep_js_ctx_attr_runpool_release_ctx()

bool kbasep_js_ctx_attr_runpool_release_ctx ( struct kbase_device kbdev,
struct kbase_context kctx 
)

Release all attributes of a context

This occurs on scheduling out the context from the runpool (but before is_scheduled is cleared)

Requires:

  • jsctx mutex
  • runpool_irq spinlock
  • ctx->is_scheduled is true
Returns
true indicates a change in ctx attributes state of the runpool. In this state, the scheduler might be able to submit more jobs than previously, and so the caller should ensure kbasep_js_try_run_next_job_nolock() or similar is called sometime later.
false indicates no change in ctx attributes state of the runpool.

◆ kbasep_js_ctx_attr_runpool_retain_ctx()

void kbasep_js_ctx_attr_runpool_retain_ctx ( struct kbase_device kbdev,
struct kbase_context kctx 
)

Retain all attributes of a context

This occurs on scheduling in the context on the runpool (but after is_scheduled is set)

Requires:

  • jsctx mutex
  • runpool_irq spinlock
  • ctx->is_scheduled is true

◆ kbasep_js_ctx_attr_set_initial_attrs()

void kbasep_js_ctx_attr_set_initial_attrs ( struct kbase_device kbdev,
struct kbase_context kctx 
)

Set the initial attributes of a context (when context create flags are set)

Requires:

  • Hold the jsctx_mutex

◆ kbasep_js_devdata_halt()

void kbasep_js_devdata_halt ( struct kbase_device kbdev)

Halt the Job Scheduler.

It is safe to call this on kbdev even if it the kbasep_js_device_data sub-structure was never initialized/failed initialization, to give efficient error-path code.

For this to work, the struct kbasep_js_device_data sub-structure of kbdev must be zero initialized before passing to the kbasep_js_devdata_init() function. This is to give efficient error path code.

It is a Programming Error to call this whilst there are still kbase_context structures registered with this scheduler.

◆ kbasep_js_devdata_init()

int kbasep_js_devdata_init ( struct kbase_device *const  kbdev)

Initialize the Job Scheduler.

The struct kbasep_js_device_data sub-structure of kbdev must be zero initialized before passing to the kbasep_js_devdata_init() function. This is to give efficient error path code.

◆ kbasep_js_devdata_term()

void kbasep_js_devdata_term ( struct kbase_device kbdev)

Terminate the Job Scheduler.

It is safe to call this on kbdev even if it the kbasep_js_device_data sub-structure was never initialized/failed initialization, to give efficient error-path code.

For this to work, the struct kbasep_js_device_data sub-structure of kbdev must be zero initialized before passing to the kbasep_js_devdata_init() function. This is to give efficient error path code.

It is a Programming Error to call this whilst there are still kbase_context structures registered with this scheduler.

◆ kbasep_js_kctx_init()

int kbasep_js_kctx_init ( struct kbase_context *const  kctx)

Initialize the Scheduling Component of a struct kbase_context on the Job Scheduler.

This effectively registers a struct kbase_context with a Job Scheduler.

It does not register any jobs owned by the struct kbase_context with the scheduler. Those must be separately registered by kbasep_js_add_job().

The struct kbase_context must be zero intitialized before passing to the kbase_js_init() function. This is to give efficient error path code.

◆ kbasep_js_kctx_term()

void kbasep_js_kctx_term ( struct kbase_context kctx)

Terminate the Scheduling Component of a struct kbase_context on the Job Scheduler.

This effectively de-registers a struct kbase_context from its Job Scheduler

It is safe to call this on a struct kbase_context that has never had or failed initialization of its jctx.sched_info member, to give efficient error-path code.

For this to work, the struct kbase_context must be zero intitialized before passing to the kbase_js_init() function.

It is a Programming Error to call this whilst there are still jobs registered with this context.

◆ kbasep_js_release_privileged_ctx()

void kbasep_js_release_privileged_ctx ( struct kbase_device kbdev,
struct kbase_context kctx 
)

Release a privileged context, allowing it to be scheduled out.

See kbasep_js_runpool_release_ctx for potential side effects.

The following locking conditions are made on the caller:

  • it must not hold the hwaccess_lock, because it will be used internally.
  • it must not hold kbasep_js_kctx_info::ctx::jsctx_mutex.
  • it must not hold kbasep_js_device_data::runpool_mutex (as this will be obtained internally)
  • it must not hold the kbase_device::mmu_hw_mutex (as this will be obtained internally)

◆ kbasep_js_remove_cancelled_job()

bool kbasep_js_remove_cancelled_job ( struct kbase_device kbdev,
struct kbase_context kctx,
struct kbase_jd_atom katom 
)

Completely remove a job chain from the Job Scheduler, in the case where the job chain was cancelled.

This is a variant of kbasep_js_remove_job() that takes care of removing all of the retained state too. This is generally useful for cancelled atoms, which need not be handled in an optimal way.

It is a programming error to call this when:

  • atom is not a job belonging to kctx.
  • atom has already been removed from the Job Scheduler.
  • atom is still in the runpool:
    • it is not being killed with kbasep_jd_cancel()

The following locking conditions are made on the caller:

  • it must hold kbasep_js_kctx_info::ctx::jsctx_mutex.
  • it must not hold the hwaccess_lock, (as this will be obtained internally)
  • it must not hold kbasep_js_device_data::runpool_mutex (as this could be obtained internally)
Returns
true indicates that ctx attributes have changed and the caller should call kbase_js_sched_all() to try to run more jobs
false otherwise

◆ kbasep_js_remove_job()

void kbasep_js_remove_job ( struct kbase_device kbdev,
struct kbase_context kctx,
struct kbase_jd_atom atom 
)

Remove a job chain from the Job Scheduler, except for its 'retained state'.

Completely removing a job requires several calls:

In the common case of atoms completing normally, this set of actions is more optimal for spinlock purposes than having kbasep_js_remove_job() handle all of the actions.

In the case of cancelling atoms, it is easier to call kbasep_js_remove_cancelled_job(), which handles all the necessary actions.

It is a programming error to call this when:

  • atom is not a job belonging to kctx.
  • atom has already been removed from the Job Scheduler.
  • atom is still in the runpool

Do not use this for removing jobs being killed by kbase_jd_cancel() - use kbasep_js_remove_cancelled_job() instead.

The following locking conditions are made on the caller:

  • it must hold kbasep_js_kctx_info::ctx::jsctx_mutex.

◆ kbasep_js_resume()

void kbasep_js_resume ( struct kbase_device kbdev)

Resume the Job Scheduler after a Power Management Resume event.

This restores the actions from kbasep_js_suspend():

  • Schedules contexts back into the runpool
  • Resumes running atoms on the GPU

◆ kbasep_js_runpool_lookup_ctx()

struct kbase_context* kbasep_js_runpool_lookup_ctx ( struct kbase_device kbdev,
int  as_nr 
)

Lookup a context in the Run Pool based upon its current address space and ensure that is stays scheduled in.

The context is refcounted as being busy to prevent it from scheduling out. It must be released with kbasep_js_runpool_release_ctx() when it is no longer required to stay scheduled in.

Note
This function can safely be called from IRQ context.

The following locking conditions are made on the caller:

  • it must not hold the hwaccess_lock, because it will be used internally. If the hwaccess_lock is already held, then the caller should use kbasep_js_runpool_lookup_ctx_nolock() instead.
Returns
a valid struct kbase_context on success, which has been refcounted as being busy.
NULL on failure, indicating that no context was found in as_nr

◆ kbasep_js_runpool_lookup_ctx_nolock()

struct kbase_context* kbasep_js_runpool_lookup_ctx_nolock ( struct kbase_device kbdev,
int  as_nr 
)

kbasep_js_runpool_lookup_ctx_nolock - Lookup a context in the Run Pool based upon its current address space and ensure that is stays scheduled in. : Device pointer : Address space to lookup

The context is refcounted as being busy to prevent it from scheduling out. It must be released with kbasep_js_runpool_release_ctx() when it is no longer required to stay scheduled in.

Note: This function can safely be called from IRQ context.

The following locking conditions are made on the caller:

  • it must the hold the hwaccess_lock

Return: a valid struct kbase_context on success, which has been refcounted as being busy. NULL on failure, indicating that no context was found in as_nr

◆ kbasep_js_runpool_release_ctx()

void kbasep_js_runpool_release_ctx ( struct kbase_device kbdev,
struct kbase_context kctx 
)

Release a refcount of a context being busy, allowing it to be scheduled out.

When the refcount reaches zero and the context might be scheduled out (depending on whether the Scheudling Policy has deemed it so, or if it has run out of jobs).

If the context does get scheduled out, then The following actions will be taken as part of deschduling a context:

  • For the context being descheduled:
    • If the context is in the processing of dying (all the jobs are being removed from it), then descheduling also kills off any jobs remaining in the context.
    • If the context is not dying, and any jobs remain after descheduling the context then it is re-enqueued to the Policy's Queue.
    • Otherwise, the context is still known to the scheduler, but remains absent from the Policy Queue until a job is next added to it.
    • In all descheduling cases, the Power Manager active reference (obtained during kbasep_js_try_schedule_head_ctx()) is released (kbase_pm_context_idle()).

Whilst the context is being descheduled, this also handles actions that cause more atoms to be run:

  • Attempt submitting atoms when the Context Attributes on the Runpool have changed. This is because the context being scheduled out could mean that there are more opportunities to run atoms.
  • Attempt submitting to a slot that was previously blocked due to affinity restrictions. This is usually only necessary when releasing a context happens as part of completing a previous job, but is harmless nonetheless.
  • Attempt scheduling in a new context (if one is available), and if necessary, running a job from that new context.

Unlike retaining a context in the runpool, this function cannot be called from IRQ context.

It is a programming error to call this on a kctx that is not currently scheduled, or that already has a zero refcount.

The following locking conditions are made on the caller:

  • it must not hold the hwaccess_lock, because it will be used internally.
  • it must not hold kbasep_js_kctx_info::ctx::jsctx_mutex.
  • it must not hold kbasep_js_device_data::runpool_mutex (as this will be obtained internally)
  • it must not hold the kbase_device::mmu_hw_mutex (as this will be obtained internally)
  • it must not hold kbasep_jd_device_data::queue_mutex (as this will be obtained internally)

◆ kbasep_js_runpool_release_ctx_and_katom_retained_state()

void kbasep_js_runpool_release_ctx_and_katom_retained_state ( struct kbase_device kbdev,
struct kbase_context kctx,
struct kbasep_js_atom_retained_state katom_retained_state 
)

Variant of kbasep_js_runpool_release_ctx() that handles additional actions from completing an atom.

This is usually called as part of completing an atom and releasing the refcount on the context held by the atom.

Therefore, the extra actions carried out are part of handling actions queued on a completed atom, namely:

  • Releasing the atom's context attributes
  • Retrying the submission on a particular slot, because we couldn't submit on that slot from an IRQ handler.

The locking conditions of this function are the same as those for kbasep_js_runpool_release_ctx()

◆ kbasep_js_runpool_requeue_or_kill_ctx()

void kbasep_js_runpool_requeue_or_kill_ctx ( struct kbase_device kbdev,
struct kbase_context kctx,
bool  has_pm_ref 
)

Handling the requeuing/killing of a context that was evicted from the policy queue or runpool.

This should be used whenever handing off a context that has been evicted from the policy queue or the runpool:

  • If the context is not dying and has jobs, it gets re-added to the policy queue
  • Otherwise, it is not added

In addition, if the context is dying the jobs are killed asynchronously.

In all cases, the Power Manager active reference is released (kbase_pm_context_idle()) whenever the has_pm_ref parameter is true. has_pm_ref must be set to false whenever the context was not previously in the runpool and does not hold a Power Manager active refcount. Note that contexts in a rollback of kbasep_js_try_schedule_head_ctx() might have an active refcount even though they weren't in the runpool.

The following locking conditions are made on the caller:

  • it must hold kbasep_js_kctx_info::ctx::jsctx_mutex.
  • it must not hold kbasep_jd_device_data::queue_mutex (as this will be obtained internally)

◆ kbasep_js_runpool_retain_ctx()

bool kbasep_js_runpool_retain_ctx ( struct kbase_device kbdev,
struct kbase_context kctx 
)

Refcount a context as being busy, preventing it from being scheduled out.

Note
This function can safely be called from IRQ context.

The following locking conditions are made on the caller:

  • it must not hold the hwaccess_lock, because it will be used internally.
Returns
value != false if the retain succeeded, and the context will not be scheduled out.
false if the retain failed (because the context is being/has been scheduled out).

◆ kbasep_js_runpool_retain_ctx_nolock()

bool kbasep_js_runpool_retain_ctx_nolock ( struct kbase_device kbdev,
struct kbase_context kctx 
)

Refcount a context as being busy, preventing it from being scheduled out.

Note
This function can safely be called from IRQ context.

The following locks must be held by the caller:

  • hwaccess_lock
Returns
value != false if the retain succeeded, and the context will not be scheduled out.
false if the retain failed (because the context is being/has been scheduled out).

◆ kbasep_js_schedule_privileged_ctx()

void kbasep_js_schedule_privileged_ctx ( struct kbase_device kbdev,
struct kbase_context kctx 
)

Schedule in a privileged context.

This schedules a context in regardless of the context priority. If the runpool is full, a context will be forced out of the runpool and the function will wait for the new context to be scheduled in. The context will be kept scheduled in (and the corresponding address space reserved) until kbasep_js_release_privileged_ctx is called).

The following locking conditions are made on the caller:

  • it must not hold the hwaccess_lock, because it will be used internally.
  • it must not hold kbasep_js_device_data::runpool_mutex (as this will be obtained internally)
  • it must not hold the kbase_device::mmu_hw_mutex (as this will be obtained internally)
  • it must not hold kbasep_jd_device_data::queue_mutex (again, it's used internally).
  • it must not hold kbasep_js_kctx_info::ctx::jsctx_mutex, because it will be used internally.

◆ kbasep_js_suspend()

void kbasep_js_suspend ( struct kbase_device kbdev)

Suspend the job scheduler during a Power Management Suspend event.

Causes all contexts to be removed from the runpool, and prevents any contexts from (re)entering the runpool.

This does not handle suspending the one privileged context: the caller must instead do this by by suspending the GPU HW Counter Instrumentation.

This will eventually cause all Power Management active references held by contexts on the runpool to be released, without running any more atoms.

The caller must then wait for all Power Mangement active refcount to become zero before completing the suspend.

The emptying mechanism may take some time to complete, since it can wait for jobs to complete naturally instead of forcing them to end quickly. However, this is bounded by the Job Scheduler's Job Timeouts. Hence, this function is guaranteed to complete in a finite time.