kernel: add function to query the current preempt count

This commit is contained in:
2023-05-01 08:26:41 +01:00
parent 194efd4b6b
commit 40762ffb95
2 changed files with 15 additions and 3 deletions

View File

@@ -17,7 +17,7 @@ enum cpu_flags {
struct cpu_data {
enum cpu_flags c_flags;
unsigned int c_id;
unsigned int c_preempt_count;
int c_preempt_count;
struct runqueue c_rq;
struct queue c_timers;
@@ -46,6 +46,7 @@ static inline cycles_t cycles_diff(cycles_t then, cycles_t now)
extern void preempt_disable(void);
extern void preempt_enable(void);
extern int preempt_count(void);
extern unsigned int cpu_get_highest_available(void);

View File

@@ -43,7 +43,7 @@ void preempt_disable(void)
return;
}
unsigned int preempt = READ_ONCE(cpu_data->c_preempt_count);
int preempt = READ_ONCE(cpu_data->c_preempt_count);
preempt++;
WRITE_ONCE(cpu_data->c_preempt_count, preempt);
}
@@ -56,7 +56,7 @@ void preempt_enable(void)
return;
}
unsigned int preempt = READ_ONCE(cpu_data->c_preempt_count);
int preempt = READ_ONCE(cpu_data->c_preempt_count);
if (preempt > 0) {
preempt--;
@@ -65,6 +65,17 @@ void preempt_enable(void)
WRITE_ONCE(cpu_data->c_preempt_count, preempt);
}
int preempt_count(void)
{
ml_cpu_block *ml_cpu = ml_this_cpu();
struct cpu_data *cpu_data = ml_cpu_block_get_data(ml_cpu);
if (!cpu_data) {
return 0;
}
return READ_ONCE(cpu_data->c_preempt_count);
}
unsigned int cpu_get_highest_available(void)
{
return bitmap_highest_set(cpu_available, CPU_MAX);