Skip to content

Commit 8c86635

Browse files
author
Fox Snowpatch
committed
1 parent 85ff933 commit 8c86635

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

arch/powerpc/include/asm/dtl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ extern struct rw_semaphore dtl_access_lock;
4040
extern void register_dtl_buffer(int cpu);
4141
extern void alloc_dtl_buffers(unsigned long *time_limit);
4242

43+
extern atomic_t dtl_count;
4344
#endif /* _ASM_POWERPC_DTL_H */

arch/powerpc/platforms/pseries/dtl.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ static u8 dtl_event_mask = DTL_LOG_ALL;
3737
*/
3838
static int dtl_buf_entries = N_DISPATCH_LOG;
3939

40+
/*
41+
* dtl_count indicates the number and type of dtl users.
42+
* 0 indicates no active users of dtl / vcpu_dispatchstats.
43+
* -1 indicates vcpudispatch_stats user is active.
44+
* 1 and above indicates active dtl users.
45+
*/
46+
atomic_t dtl_count;
47+
4048
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
4149

4250
/*
@@ -56,8 +64,6 @@ struct dtl_ring {
5664

5765
static DEFINE_PER_CPU(struct dtl_ring, dtl_rings);
5866

59-
static atomic_t dtl_count;
60-
6167
/*
6268
* The cpu accounting code controls the DTL ring buffer, and we get
6369
* given entries as they are processed.
@@ -158,7 +164,7 @@ static int dtl_start(struct dtl *dtl)
158164

159165
/* enable event logging */
160166
lppaca_of(dtl->cpu).dtl_enable_mask = dtl_event_mask;
161-
167+
atomic_inc(&dtl_count);
162168
return 0;
163169
}
164170

@@ -169,6 +175,7 @@ static void dtl_stop(struct dtl *dtl)
169175
lppaca_of(dtl->cpu).dtl_enable_mask = 0x0;
170176

171177
unregister_dtl(hwcpu);
178+
atomic_dec(&dtl_count);
172179
}
173180

174181
static u64 dtl_current_index(struct dtl *dtl)
@@ -194,6 +201,11 @@ static int dtl_enable(struct dtl *dtl)
194201
if (!down_read_trylock(&dtl_access_lock))
195202
return -EBUSY;
196203

204+
if (atomic_read(&dtl_count) == -1) {
205+
up_read(&dtl_access_lock);
206+
return -EBUSY;
207+
}
208+
197209
n_entries = dtl_buf_entries;
198210
buf = kmem_cache_alloc_node(dtl_cache, GFP_KERNEL, cpu_to_node(dtl->cpu));
199211
if (!buf) {

arch/powerpc/platforms/pseries/lpar.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ static DEFINE_PER_CPU(struct vcpu_dispatch_data, vcpu_disp_data);
175175
static DEFINE_PER_CPU(u64, dtl_entry_ridx);
176176
static DEFINE_PER_CPU(struct dtl_worker, dtl_workers);
177177
static enum cpuhp_state dtl_worker_state;
178-
static DEFINE_MUTEX(dtl_enable_mutex);
179178
static int vcpudispatch_stats_on __read_mostly;
180179
static int vcpudispatch_stats_freq = 50;
181180
static __be32 *vcpu_associativity, *pcpu_associativity;
@@ -464,7 +463,8 @@ static int dtl_worker_enable(unsigned long *time_limit)
464463
{
465464
int rc = 0, state;
466465

467-
if (!down_write_trylock(&dtl_access_lock)) {
466+
/* Return if dtl is already active */
467+
if (atomic_read(&dtl_count) != 0) {
468468
rc = -EBUSY;
469469
goto out;
470470
}
@@ -480,11 +480,11 @@ static int dtl_worker_enable(unsigned long *time_limit)
480480
pr_err("vcpudispatch_stats: unable to setup workqueue for DTL processing\n");
481481
free_dtl_buffers(time_limit);
482482
reset_global_dtl_mask();
483-
up_write(&dtl_access_lock);
484483
rc = -EINVAL;
485484
goto out;
486485
}
487486
dtl_worker_state = state;
487+
atomic_set(&dtl_count, -1);
488488

489489
out:
490490
return rc;
@@ -495,7 +495,7 @@ static void dtl_worker_disable(unsigned long *time_limit)
495495
cpuhp_remove_state(dtl_worker_state);
496496
free_dtl_buffers(time_limit);
497497
reset_global_dtl_mask();
498-
up_write(&dtl_access_lock);
498+
atomic_set(&dtl_count, 0);
499499
}
500500

501501
static ssize_t vcpudispatch_stats_write(struct file *file, const char __user *p,
@@ -519,7 +519,8 @@ static ssize_t vcpudispatch_stats_write(struct file *file, const char __user *p,
519519
return rc ? rc : -EINVAL;
520520
}
521521

522-
mutex_lock(&dtl_enable_mutex);
522+
if (!down_write_trylock(&dtl_access_lock))
523+
return -EBUSY;
523524

524525
if ((cmd == 0 && !vcpudispatch_stats_on) ||
525526
(cmd == 1 && vcpudispatch_stats_on))
@@ -551,7 +552,7 @@ static ssize_t vcpudispatch_stats_write(struct file *file, const char __user *p,
551552
vcpudispatch_stats_on = cmd;
552553

553554
out:
554-
mutex_unlock(&dtl_enable_mutex);
555+
up_write(&dtl_access_lock);
555556
if (rc)
556557
return rc;
557558
return count;

0 commit comments

Comments
 (0)