mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-25 08:14:45 +02:00
ThreadManager: Add a simple priority field.
Currently, not actually respected.
This commit is contained in:
@@ -6,13 +6,17 @@
|
||||
|
||||
class LoopRangeTask : public Task {
|
||||
public:
|
||||
LoopRangeTask(WaitableCounter *counter, const std::function<void(int, int)> &loop, int lower, int upper)
|
||||
: counter_(counter), loop_(loop), lower_(lower), upper_(upper) {}
|
||||
LoopRangeTask(WaitableCounter *counter, const std::function<void(int, int)> &loop, int lower, int upper, TaskPriority p)
|
||||
: counter_(counter), loop_(loop), lower_(lower), upper_(upper), priority_(p) {}
|
||||
|
||||
TaskType Type() const override {
|
||||
return TaskType::CPU_COMPUTE;
|
||||
}
|
||||
|
||||
TaskPriority Priority() const override {
|
||||
return priority_;
|
||||
}
|
||||
|
||||
void Run() override {
|
||||
loop_(lower_, upper_);
|
||||
counter_->Count();
|
||||
@@ -23,9 +27,10 @@ public:
|
||||
|
||||
int lower_;
|
||||
int upper_;
|
||||
const TaskPriority priority_;
|
||||
};
|
||||
|
||||
WaitableCounter *ParallelRangeLoopWaitable(ThreadManager *threadMan, const std::function<void(int, int)> &loop, int lower, int upper, int minSize) {
|
||||
WaitableCounter *ParallelRangeLoopWaitable(ThreadManager *threadMan, const std::function<void(int, int)> &loop, int lower, int upper, int minSize, TaskPriority priority) {
|
||||
if (minSize == -1) {
|
||||
minSize = 1;
|
||||
}
|
||||
@@ -38,7 +43,7 @@ WaitableCounter *ParallelRangeLoopWaitable(ThreadManager *threadMan, const std::
|
||||
} else if (range <= minSize) {
|
||||
// Single background task.
|
||||
WaitableCounter *waitableCounter = new WaitableCounter(1);
|
||||
threadMan->EnqueueTaskOnThread(0, new LoopRangeTask(waitableCounter, loop, lower, upper));
|
||||
threadMan->EnqueueTaskOnThread(0, new LoopRangeTask(waitableCounter, loop, lower, upper, priority));
|
||||
return waitableCounter;
|
||||
} else {
|
||||
// Split the range between threads. Allow for some fractional bits.
|
||||
@@ -65,7 +70,7 @@ WaitableCounter *ParallelRangeLoopWaitable(ThreadManager *threadMan, const std::
|
||||
// Let's do the stragglers on the current thread.
|
||||
break;
|
||||
}
|
||||
threadMan->EnqueueTaskOnThread(i, new LoopRangeTask(waitableCounter, loop, start, end));
|
||||
threadMan->EnqueueTaskOnThread(i, new LoopRangeTask(waitableCounter, loop, start, end, priority));
|
||||
counter += delta;
|
||||
if ((counter >> fractionalBits) >= upper) {
|
||||
break;
|
||||
@@ -83,7 +88,7 @@ WaitableCounter *ParallelRangeLoopWaitable(ThreadManager *threadMan, const std::
|
||||
}
|
||||
}
|
||||
|
||||
void ParallelRangeLoop(ThreadManager *threadMan, const std::function<void(int, int)> &loop, int lower, int upper, int minSize) {
|
||||
void ParallelRangeLoop(ThreadManager *threadMan, const std::function<void(int, int)> &loop, int lower, int upper, int minSize, TaskPriority priority) {
|
||||
if (cpu_info.num_cores == 1 || (minSize >= (upper - lower) && upper > lower)) {
|
||||
// "Optimization" for single-core devices, or minSize larger than the range.
|
||||
// No point in adding threading overhead, let's just do it inline (since this is the blocking variant).
|
||||
@@ -96,7 +101,7 @@ void ParallelRangeLoop(ThreadManager *threadMan, const std::function<void(int, i
|
||||
minSize = 1;
|
||||
}
|
||||
|
||||
WaitableCounter *counter = ParallelRangeLoopWaitable(threadMan, loop, lower, upper, minSize);
|
||||
WaitableCounter *counter = ParallelRangeLoopWaitable(threadMan, loop, lower, upper, minSize, priority);
|
||||
// TODO: Optimize using minSize. We'll just compute whether there's a remainer, remove it from the call to ParallelRangeLoopWaitable,
|
||||
// and process the remainder right here. If there's no remainer, we'll steal a whole chunk.
|
||||
if (counter) {
|
||||
@@ -105,7 +110,7 @@ void ParallelRangeLoop(ThreadManager *threadMan, const std::function<void(int, i
|
||||
}
|
||||
|
||||
// NOTE: Supports a max of 2GB.
|
||||
void ParallelMemcpy(ThreadManager *threadMan, void *dst, const void *src, size_t bytes) {
|
||||
void ParallelMemcpy(ThreadManager *threadMan, void *dst, const void *src, size_t bytes, TaskPriority priority) {
|
||||
// This threshold can probably be a lot bigger.
|
||||
if (bytes < 512) {
|
||||
memcpy(dst, src, bytes);
|
||||
@@ -118,11 +123,11 @@ void ParallelMemcpy(ThreadManager *threadMan, void *dst, const void *src, size_t
|
||||
const char *s = (const char *)src;
|
||||
ParallelRangeLoop(threadMan, [&](int l, int h) {
|
||||
memmove(d + l, s + l, h - l);
|
||||
}, 0, (int)bytes, 128 * 1024);
|
||||
}, 0, (int)bytes, 128 * 1024, priority);
|
||||
}
|
||||
|
||||
// NOTE: Supports a max of 2GB.
|
||||
void ParallelMemset(ThreadManager *threadMan, void *dst, uint8_t value, size_t bytes) {
|
||||
void ParallelMemset(ThreadManager *threadMan, void *dst, uint8_t value, size_t bytes, TaskPriority priority) {
|
||||
// This threshold can probably be a lot bigger.
|
||||
if (bytes < 512) {
|
||||
memset(dst, 0, bytes);
|
||||
@@ -134,5 +139,5 @@ void ParallelMemset(ThreadManager *threadMan, void *dst, uint8_t value, size_t b
|
||||
char *d = (char *)dst;
|
||||
ParallelRangeLoop(threadMan, [&](int l, int h) {
|
||||
memset(d + l, value, h - l);
|
||||
}, 0, (int)bytes, 128 * 1024);
|
||||
}, 0, (int)bytes, 128 * 1024, priority);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user