Skip to content

Commit

Permalink
Merge pull request vitasdk#694 from isage/affinity
Browse files Browse the repository at this point in the history
Add thread cpu affinity functions. Fix thread attr function.
  • Loading branch information
Princess-of-Sleeping authored Apr 18, 2022
2 parents 6348f75 + f7ddbc2 commit ad6a816
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
9 changes: 9 additions & 0 deletions include/psp2/kernel/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
#ifndef _PSP2_KERNEL_CPU_H_
#define _PSP2_KERNEL_CPU_H_

#define SCE_KERNEL_CPU_MASK_USER_0 0x00010000
#define SCE_KERNEL_CPU_MASK_USER_1 0x00020000
#define SCE_KERNEL_CPU_MASK_USER_2 0x00040000
#define SCE_KERNEL_CPU_MASK_SYSTEM 0x00080000

#define SCE_KERNEL_CPU_MASK_USER_ALL \
(SCE_KERNEL_CPU_MASK_USER_0 | SCE_KERNEL_CPU_MASK_USER_1 | SCE_KERNEL_CPU_MASK_USER_2)


#ifdef __cplusplus
extern "C" {
#endif
Expand Down
39 changes: 36 additions & 3 deletions include/psp2/kernel/threadmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#define _PSP2_KERNEL_THREADMGR_H_

#include <psp2/types.h>
#include <psp2/kernel/cpu.h>

/** Inherit calling thread affinity mask. */
#define SCE_KERNEL_THREAD_CPU_AFFINITY_MASK_DEFAULT (0)

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -125,6 +129,16 @@ typedef enum SceKernelMutexAttribute {
* @param stackSize - The size of the initial stack.
* @param attr - The thread attributes, zero or more of ::SceThreadAttributes.
* @param cpuAffinityMask - The CPU affinity mask
* A thread can run only on the cores specified in the CPU affinity mask.
* The CPU affinity mask can be specified by the logical sum of the following macros:
* - SCE_KERNEL_CPU_MASK_USER_0
* - SCE_KERNEL_CPU_MASK_USER_1
* - SCE_KERNEL_CPU_MASK_USER_2
* - SCE_KERNEL_CPU_MASK_SYSTEM (system-reserved core)
* The following macro are also available to represent all available in userland CPU cores:
* - SCE_KERNEL_CPU_MASK_USER_ALL
* The following macro are also available to inherit affinity mask of the calling process:
* - SCE_KERNEL_THREAD_CPU_AFFINITY_MASK_DEFAULT
* @param option - Additional options specified by ::SceKernelThreadOptParam.
* @return UID of the created thread, or an error code.
Expand Down Expand Up @@ -214,12 +228,12 @@ int sceKernelDelayThreadCB(SceUInt delay);
/**
* Modify the attributes of the current thread.
*
* @param unknown - Set to 0.
* @param attr - The thread attributes to modify. One of ::SceThreadAttributes.
* @param clearAttr - The thread attributes to clear. One of ::SceThreadAttributes.
* @param setAttr - The thread attributes to set. One of ::SceThreadAttributes.
*
* @return < 0 on error.
*/
int sceKernelChangeCurrentThreadAttr(int unknown, SceUInt attr);
int sceKernelChangeCurrentThreadAttr(SceUInt clearAttr, SceUInt setAttr);

/**
* Change the threads current priority.
Expand Down Expand Up @@ -313,6 +327,25 @@ int sceKernelGetThreadInfo(SceUID thid, SceKernelThreadInfo *info);
*/
int sceKernelGetThreadRunStatus(SceUID thid, SceKernelThreadRunStatus *status);

/**
* Retrive the cpu affinity mask of a thread.
*
* @param thid - UID of the thread to retrieve affinity mask for.
*
* @return current affinity mask if >= 0, otherwise the error code.
*/
int sceKernelGetThreadCpuAffinityMask(SceUID thid);

/**
* Set the cpu affinity mask of a thread.
*
* @param thid - UID of the thread to retrieve affinity mask for.
* @param mask - New cpu affinity mask.
*
* @return 0 if successful, otherwise the error code.
*/
int sceKernelChangeThreadCpuAffinityMask(SceUID thid, int mask);


/* Semaphores. */

Expand Down

0 comments on commit ad6a816

Please sign in to comment.