* [PATCH] lib: proportions.c: Remove some unused functions
@ 2014-12-20 14:51 Rickard Strandqvist
2014-12-22 21:26 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Rickard Strandqvist @ 2014-12-20 14:51 UTC (permalink / raw)
To: Tejun Heo, Jan Kara; +Cc: Rickard Strandqvist, David S. Miller, linux-kernel
Removes some functions that are not used anywhere:
prop_change_shift() prop_descriptor_init() prop_fraction_percpu() prop_fraction_single() __prop_inc_percpu_max() prop_local_destroy_percpu() prop_local_destroy_single() prop_local_init_percpu() prop_local_init_single()
This was partially found by using a static code analysis program called cppcheck.
Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
include/linux/proportions.h | 14 ----
lib/proportions.c | 177 -------------------------------------------
2 files changed, 191 deletions(-)
diff --git a/include/linux/proportions.h b/include/linux/proportions.h
index 00e8e8f..494b1a6 100644
--- a/include/linux/proportions.h
+++ b/include/linux/proportions.h
@@ -41,9 +41,6 @@ struct prop_descriptor {
struct mutex mutex; /* serialize the prop_global switch */
};
-int prop_descriptor_init(struct prop_descriptor *pd, int shift, gfp_t gfp);
-void prop_change_shift(struct prop_descriptor *pd, int new_shift);
-
/*
* ----- PERCPU ------
*/
@@ -62,11 +59,7 @@ struct prop_local_percpu {
raw_spinlock_t lock; /* protect the snapshot state */
};
-int prop_local_init_percpu(struct prop_local_percpu *pl, gfp_t gfp);
-void prop_local_destroy_percpu(struct prop_local_percpu *pl);
void __prop_inc_percpu(struct prop_descriptor *pd, struct prop_local_percpu *pl);
-void prop_fraction_percpu(struct prop_descriptor *pd, struct prop_local_percpu *pl,
- long *numerator, long *denominator);
static inline
void prop_inc_percpu(struct prop_descriptor *pd, struct prop_local_percpu *pl)
@@ -91,9 +84,6 @@ void prop_inc_percpu(struct prop_descriptor *pd, struct prop_local_percpu *pl)
#define PROP_FRAC_SHIFT (BITS_PER_LONG - PROP_MAX_SHIFT - 1)
#define PROP_FRAC_BASE (1UL << PROP_FRAC_SHIFT)
-void __prop_inc_percpu_max(struct prop_descriptor *pd,
- struct prop_local_percpu *pl, long frac);
-
/*
* ----- SINGLE ------
@@ -118,11 +108,7 @@ struct prop_local_single {
{ .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \
}
-int prop_local_init_single(struct prop_local_single *pl);
-void prop_local_destroy_single(struct prop_local_single *pl);
void __prop_inc_single(struct prop_descriptor *pd, struct prop_local_single *pl);
-void prop_fraction_single(struct prop_descriptor *pd, struct prop_local_single *pl,
- long *numerator, long *denominator);
static inline
void prop_inc_single(struct prop_descriptor *pd, struct prop_local_single *pl)
diff --git a/lib/proportions.c b/lib/proportions.c
index 6f72429..b953cc2 100644
--- a/lib/proportions.c
+++ b/lib/proportions.c
@@ -73,75 +73,6 @@
#include <linux/proportions.h>
#include <linux/rcupdate.h>
-int prop_descriptor_init(struct prop_descriptor *pd, int shift, gfp_t gfp)
-{
- int err;
-
- if (shift > PROP_MAX_SHIFT)
- shift = PROP_MAX_SHIFT;
-
- pd->index = 0;
- pd->pg[0].shift = shift;
- mutex_init(&pd->mutex);
- err = percpu_counter_init(&pd->pg[0].events, 0, gfp);
- if (err)
- goto out;
-
- err = percpu_counter_init(&pd->pg[1].events, 0, gfp);
- if (err)
- percpu_counter_destroy(&pd->pg[0].events);
-
-out:
- return err;
-}
-
-/*
- * We have two copies, and flip between them to make it seem like an atomic
- * update. The update is not really atomic wrt the events counter, but
- * it is internally consistent with the bit layout depending on shift.
- *
- * We copy the events count, move the bits around and flip the index.
- */
-void prop_change_shift(struct prop_descriptor *pd, int shift)
-{
- int index;
- int offset;
- u64 events;
- unsigned long flags;
-
- if (shift > PROP_MAX_SHIFT)
- shift = PROP_MAX_SHIFT;
-
- mutex_lock(&pd->mutex);
-
- index = pd->index ^ 1;
- offset = pd->pg[pd->index].shift - shift;
- if (!offset)
- goto out;
-
- pd->pg[index].shift = shift;
-
- local_irq_save(flags);
- events = percpu_counter_sum(&pd->pg[pd->index].events);
- if (offset < 0)
- events <<= -offset;
- else
- events >>= offset;
- percpu_counter_set(&pd->pg[index].events, events);
-
- /*
- * ensure the new pg is fully written before the switch
- */
- smp_wmb();
- pd->index = index;
- local_irq_restore(flags);
-
- synchronize_rcu();
-
-out:
- mutex_unlock(&pd->mutex);
-}
-
/*
* wrap the access to the data in an rcu_read_lock() section;
* this is used to track the active references.
@@ -188,19 +119,6 @@ prop_adjust_shift(int *pl_shift, unsigned long *pl_period, int new_shift)
#define PROP_BATCH (8*(1+ilog2(nr_cpu_ids)))
-int prop_local_init_percpu(struct prop_local_percpu *pl, gfp_t gfp)
-{
- raw_spin_lock_init(&pl->lock);
- pl->shift = 0;
- pl->period = 0;
- return percpu_counter_init(&pl->events, 0, gfp);
-}
-
-void prop_local_destroy_percpu(struct prop_local_percpu *pl)
-{
- percpu_counter_destroy(&pl->events);
-}
-
/*
* Catch up with missed period expirations.
*
@@ -264,78 +182,6 @@ void __prop_inc_percpu(struct prop_descriptor *pd, struct prop_local_percpu *pl)
}
/*
- * identical to __prop_inc_percpu, except that it limits this pl's fraction to
- * @frac/PROP_FRAC_BASE by ignoring events when this limit has been exceeded.
- */
-void __prop_inc_percpu_max(struct prop_descriptor *pd,
- struct prop_local_percpu *pl, long frac)
-{
- struct prop_global *pg = prop_get_global(pd);
-
- prop_norm_percpu(pg, pl);
-
- if (unlikely(frac != PROP_FRAC_BASE)) {
- unsigned long period_2 = 1UL << (pg->shift - 1);
- unsigned long counter_mask = period_2 - 1;
- unsigned long global_count;
- long numerator, denominator;
-
- numerator = percpu_counter_read_positive(&pl->events);
- global_count = percpu_counter_read(&pg->events);
- denominator = period_2 + (global_count & counter_mask);
-
- if (numerator > ((denominator * frac) >> PROP_FRAC_SHIFT))
- goto out_put;
- }
-
- percpu_counter_add(&pl->events, 1);
- percpu_counter_add(&pg->events, 1);
-
-out_put:
- prop_put_global(pd, pg);
-}
-
-/*
- * Obtain a fraction of this proportion
- *
- * p_{j} = x_{j} / (period/2 + t % period/2)
- */
-void prop_fraction_percpu(struct prop_descriptor *pd,
- struct prop_local_percpu *pl,
- long *numerator, long *denominator)
-{
- struct prop_global *pg = prop_get_global(pd);
- unsigned long period_2 = 1UL << (pg->shift - 1);
- unsigned long counter_mask = period_2 - 1;
- unsigned long global_count;
-
- prop_norm_percpu(pg, pl);
- *numerator = percpu_counter_read_positive(&pl->events);
-
- global_count = percpu_counter_read(&pg->events);
- *denominator = period_2 + (global_count & counter_mask);
-
- prop_put_global(pd, pg);
-}
-
-/*
- * SINGLE
- */
-
-int prop_local_init_single(struct prop_local_single *pl)
-{
- raw_spin_lock_init(&pl->lock);
- pl->shift = 0;
- pl->period = 0;
- pl->events = 0;
- return 0;
-}
-
-void prop_local_destroy_single(struct prop_local_single *pl)
-{
-}
-
-/*
* Catch up with missed period expirations.
*/
static
@@ -382,26 +228,3 @@ void __prop_inc_single(struct prop_descriptor *pd, struct prop_local_single *pl)
percpu_counter_add(&pg->events, 1);
prop_put_global(pd, pg);
}
-
-/*
- * Obtain a fraction of this proportion
- *
- * p_{j} = x_{j} / (period/2 + t % period/2)
- */
-void prop_fraction_single(struct prop_descriptor *pd,
- struct prop_local_single *pl,
- long *numerator, long *denominator)
-{
- struct prop_global *pg = prop_get_global(pd);
- unsigned long period_2 = 1UL << (pg->shift - 1);
- unsigned long counter_mask = period_2 - 1;
- unsigned long global_count;
-
- prop_norm_single(pg, pl);
- *numerator = pl->events;
-
- global_count = percpu_counter_read(&pg->events);
- *denominator = period_2 + (global_count & counter_mask);
-
- prop_put_global(pd, pg);
-}
--
1.7.10.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lib: proportions.c: Remove some unused functions
2014-12-20 14:51 [PATCH] lib: proportions.c: Remove some unused functions Rickard Strandqvist
@ 2014-12-22 21:26 ` Andrew Morton
2015-01-02 17:28 ` Jan Kara
2015-01-13 14:16 ` Peter Zijlstra
0 siblings, 2 replies; 4+ messages in thread
From: Andrew Morton @ 2014-12-22 21:26 UTC (permalink / raw)
To: Rickard Strandqvist
Cc: Tejun Heo, Jan Kara, David S. Miller, linux-kernel, Peter Zijlstra
On Sat, 20 Dec 2014 15:51:53 +0100 Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se> wrote:
> Removes some functions that are not used anywhere:
> prop_change_shift() prop_descriptor_init() prop_fraction_percpu() prop_fraction_single() __prop_inc_percpu_max() prop_local_destroy_percpu() prop_local_destroy_single() prop_local_init_percpu() prop_local_init_single()
>
> This was partially found by using a static code analysis program called cppcheck.
>
> ---
> include/linux/proportions.h | 14 ----
> lib/proportions.c | 177 -------------------------------------------
> 2 files changed, 191 deletions(-)
Gee, that's a heck of a lot of dead code.
Peter, what was the thinking here? Was this code once used, or added
for API completeness or what?
Perhaps we should just ifdef it out, so the code is still sitting there if
someone wishes to resurrect it.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lib: proportions.c: Remove some unused functions
2014-12-22 21:26 ` Andrew Morton
@ 2015-01-02 17:28 ` Jan Kara
2015-01-13 14:16 ` Peter Zijlstra
1 sibling, 0 replies; 4+ messages in thread
From: Jan Kara @ 2015-01-02 17:28 UTC (permalink / raw)
To: Andrew Morton
Cc: Rickard Strandqvist, Tejun Heo, Jan Kara, David S. Miller,
linux-kernel, Peter Zijlstra
On Mon 22-12-14 13:26:26, Andrew Morton wrote:
> On Sat, 20 Dec 2014 15:51:53 +0100 Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se> wrote:
>
> > Removes some functions that are not used anywhere:
> > prop_change_shift() prop_descriptor_init() prop_fraction_percpu() prop_fraction_single() __prop_inc_percpu_max() prop_local_destroy_percpu() prop_local_destroy_single() prop_local_init_percpu() prop_local_init_single()
> >
> > This was partially found by using a static code analysis program called cppcheck.
> >
> > ---
> > include/linux/proportions.h | 14 ----
> > lib/proportions.c | 177 -------------------------------------------
> > 2 files changed, 191 deletions(-)
>
> Gee, that's a heck of a lot of dead code.
>
> Peter, what was the thinking here? Was this code once used, or added
> for API completeness or what?
>
> Perhaps we should just ifdef it out, so the code is still sitting there if
> someone wishes to resurrect it.
I believe the reason was API completeness. Ifdefing the code out looks
like a sensible thing to do - although I would be happier if we at least
compile-tested the code... Isn't there some config option we could key off
to detect something like all-yes config build?
Honza
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lib: proportions.c: Remove some unused functions
2014-12-22 21:26 ` Andrew Morton
2015-01-02 17:28 ` Jan Kara
@ 2015-01-13 14:16 ` Peter Zijlstra
1 sibling, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2015-01-13 14:16 UTC (permalink / raw)
To: Andrew Morton
Cc: Rickard Strandqvist, Tejun Heo, Jan Kara, David S. Miller, linux-kernel
On Mon, Dec 22, 2014 at 01:26:26PM -0800, Andrew Morton wrote:
> On Sat, 20 Dec 2014 15:51:53 +0100 Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se> wrote:
>
> > Removes some functions that are not used anywhere:
> > prop_change_shift() prop_descriptor_init() prop_fraction_percpu() prop_fraction_single() __prop_inc_percpu_max() prop_local_destroy_percpu() prop_local_destroy_single() prop_local_init_percpu() prop_local_init_single()
> >
> > This was partially found by using a static code analysis program called cppcheck.
> >
> > ---
> > include/linux/proportions.h | 14 ----
> > lib/proportions.c | 177 -------------------------------------------
> > 2 files changed, 191 deletions(-)
>
> Gee, that's a heck of a lot of dead code.
>
> Peter, what was the thinking here? Was this code once used, or added
> for API completeness or what?
Some of it was used once, we changed the BDI code over to the flexible
proportion code from Honza, that removed
> Perhaps we should just ifdef it out, so the code is still sitting there if
> someone wishes to resurrect it.
If there are still users of the !flex proportion code I would argue to
just leave it sit there for API completeness. It doesn't actually harm
anyone. Linkers are very good at removing dead code.
If there are in fact no users left of the !flex proportion code, then we
should just kill the entire thing.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-01-13 14:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-20 14:51 [PATCH] lib: proportions.c: Remove some unused functions Rickard Strandqvist
2014-12-22 21:26 ` Andrew Morton
2015-01-02 17:28 ` Jan Kara
2015-01-13 14:16 ` Peter Zijlstra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome