Message ID | 1527005119-6842-3-git-send-email-Dave.Martin@arm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Dave Martin <Dave.Martin@arm.com> writes: > There are a number of bits of code sprinkled around the kernel to > set a thread flag if a certain condition is true, and clear it > otherwise. > > To help make those call sites terser and less cumbersome, this > patch adds a new family of thread flag manipulators > > update*_thread_flag([...,] flag, cond) > > which do the equivalent of: > > if (cond) > set*_thread_flag([...,] flag); > else > clear*_thread_flag([...,] flag); > > Signed-off-by: Dave Martin <Dave.Martin@arm.com> > Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org> > Acked-by: Marc Zyngier <marc.zyngier@arm.com> > Acked-by: Catalin Marinas <catalin.marinas@arm.com> > Cc: Ingo Molnar <mingo@redhat.com> > Cc: Peter Zijlstra <peterz@infradead.org> > Cc: Oleg Nesterov <oleg@redhat.com> > --- > include/linux/sched.h | 6 ++++++ > include/linux/thread_info.h | 11 +++++++++++ > 2 files changed, 17 insertions(+) > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index b3d697f..c2c3051 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -1578,6 +1578,12 @@ static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag) > clear_ti_thread_flag(task_thread_info(tsk), flag); > } > > +static inline void update_tsk_thread_flag(struct task_struct *tsk, int flag, > + bool value) > +{ > + update_ti_thread_flag(task_thread_info(tsk), flag, value); > +} > + > static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag) > { > return test_and_set_ti_thread_flag(task_thread_info(tsk), flag); > diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h > index cf2862b..8d8821b 100644 > --- a/include/linux/thread_info.h > +++ b/include/linux/thread_info.h > @@ -60,6 +60,15 @@ static inline void clear_ti_thread_flag(struct thread_info *ti, int flag) > clear_bit(flag, (unsigned long *)&ti->flags); > } > > +static inline void update_ti_thread_flag(struct thread_info *ti, int flag, > + bool value) > +{ > + if (value) > + set_ti_thread_flag(ti, flag); > + else > + clear_ti_thread_flag(ti, flag); > +} > + value does seem a bit of vanilla non-informative name for a condition flag but whatever: Reviewed-by: Alex Bennée <alex.bennee@linaro.org> > static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag) > { > return test_and_set_bit(flag, (unsigned long *)&ti->flags); > @@ -79,6 +88,8 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag) > set_ti_thread_flag(current_thread_info(), flag) > #define clear_thread_flag(flag) \ > clear_ti_thread_flag(current_thread_info(), flag) > +#define update_thread_flag(flag, value) \ > + update_ti_thread_flag(current_thread_info(), flag, value) > #define test_and_set_thread_flag(flag) \ > test_and_set_ti_thread_flag(current_thread_info(), flag) > #define test_and_clear_thread_flag(flag) \ -- Alex Bennée
On Wed, May 23, 2018 at 02:46:52PM +0100, Alex Bennée wrote: > > Dave Martin <Dave.Martin@arm.com> writes: > > > There are a number of bits of code sprinkled around the kernel to > > set a thread flag if a certain condition is true, and clear it > > otherwise. > > > > To help make those call sites terser and less cumbersome, this > > patch adds a new family of thread flag manipulators > > > > update*_thread_flag([...,] flag, cond) > > > > which do the equivalent of: > > > > if (cond) > > set*_thread_flag([...,] flag); > > else > > clear*_thread_flag([...,] flag); > > > > Signed-off-by: Dave Martin <Dave.Martin@arm.com> > > Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org> > > Acked-by: Marc Zyngier <marc.zyngier@arm.com> > > Acked-by: Catalin Marinas <catalin.marinas@arm.com> > > Cc: Ingo Molnar <mingo@redhat.com> > > Cc: Peter Zijlstra <peterz@infradead.org> > > Cc: Oleg Nesterov <oleg@redhat.com> > > --- > > include/linux/sched.h | 6 ++++++ > > include/linux/thread_info.h | 11 +++++++++++ > > 2 files changed, 17 insertions(+) > > [...] > > diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h > > index cf2862b..8d8821b 100644 > > --- a/include/linux/thread_info.h > > +++ b/include/linux/thread_info.h > > @@ -60,6 +60,15 @@ static inline void clear_ti_thread_flag(struct thread_info *ti, int flag) > > clear_bit(flag, (unsigned long *)&ti->flags); > > } > > > > +static inline void update_ti_thread_flag(struct thread_info *ti, int flag, > > + bool value) > > +{ > > + if (value) > > + set_ti_thread_flag(ti, flag); > > + else > > + clear_ti_thread_flag(ti, flag); > > +} > > + > > value does seem a bit of vanilla non-informative name for a condition > flag but whatever: > > Reviewed-by: Alex Bennée <alex.bennee@linaro.org> I guess, though I couldn't some up with an obviously better name. I support "condition" would have worked, but it's more verbose. Thanks for the review ---Dave
Dave Martin <Dave.Martin@arm.com> writes: > On Wed, May 23, 2018 at 02:46:52PM +0100, Alex Bennée wrote: >> >> Dave Martin <Dave.Martin@arm.com> writes: >> >> > There are a number of bits of code sprinkled around the kernel to >> > set a thread flag if a certain condition is true, and clear it >> > otherwise. >> > >> > To help make those call sites terser and less cumbersome, this >> > patch adds a new family of thread flag manipulators >> > >> > update*_thread_flag([...,] flag, cond) >> > >> > which do the equivalent of: >> > >> > if (cond) >> > set*_thread_flag([...,] flag); >> > else >> > clear*_thread_flag([...,] flag); >> > >> > Signed-off-by: Dave Martin <Dave.Martin@arm.com> >> > Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org> >> > Acked-by: Marc Zyngier <marc.zyngier@arm.com> >> > Acked-by: Catalin Marinas <catalin.marinas@arm.com> >> > Cc: Ingo Molnar <mingo@redhat.com> >> > Cc: Peter Zijlstra <peterz@infradead.org> >> > Cc: Oleg Nesterov <oleg@redhat.com> >> > --- >> > include/linux/sched.h | 6 ++++++ >> > include/linux/thread_info.h | 11 +++++++++++ >> > 2 files changed, 17 insertions(+) >> > > > [...] > >> > diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h >> > index cf2862b..8d8821b 100644 >> > --- a/include/linux/thread_info.h >> > +++ b/include/linux/thread_info.h >> > @@ -60,6 +60,15 @@ static inline void clear_ti_thread_flag(struct thread_info *ti, int flag) >> > clear_bit(flag, (unsigned long *)&ti->flags); >> > } >> > >> > +static inline void update_ti_thread_flag(struct thread_info *ti, int flag, >> > + bool value) >> > +{ >> > + if (value) >> > + set_ti_thread_flag(ti, flag); >> > + else >> > + clear_ti_thread_flag(ti, flag); >> > +} >> > + >> >> value does seem a bit of vanilla non-informative name for a condition >> flag but whatever: >> >> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> > > I guess, though I couldn't some up with an obviously better name. > > I support "condition" would have worked, but it's more verbose. Well as you use cond in the text I think cond would also work as an abbreviated variable name. But its a minor nit ;-) > > Thanks for the review > ---Dave -- Alex Bennée
diff --git a/include/linux/sched.h b/include/linux/sched.h index b3d697f..c2c3051 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1578,6 +1578,12 @@ static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag) clear_ti_thread_flag(task_thread_info(tsk), flag); } +static inline void update_tsk_thread_flag(struct task_struct *tsk, int flag, + bool value) +{ + update_ti_thread_flag(task_thread_info(tsk), flag, value); +} + static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag) { return test_and_set_ti_thread_flag(task_thread_info(tsk), flag); diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h index cf2862b..8d8821b 100644 --- a/include/linux/thread_info.h +++ b/include/linux/thread_info.h @@ -60,6 +60,15 @@ static inline void clear_ti_thread_flag(struct thread_info *ti, int flag) clear_bit(flag, (unsigned long *)&ti->flags); } +static inline void update_ti_thread_flag(struct thread_info *ti, int flag, + bool value) +{ + if (value) + set_ti_thread_flag(ti, flag); + else + clear_ti_thread_flag(ti, flag); +} + static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag) { return test_and_set_bit(flag, (unsigned long *)&ti->flags); @@ -79,6 +88,8 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag) set_ti_thread_flag(current_thread_info(), flag) #define clear_thread_flag(flag) \ clear_ti_thread_flag(current_thread_info(), flag) +#define update_thread_flag(flag, value) \ + update_ti_thread_flag(current_thread_info(), flag, value) #define test_and_set_thread_flag(flag) \ test_and_set_ti_thread_flag(current_thread_info(), flag) #define test_and_clear_thread_flag(flag) \