All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Input :Optimize input_dev_release_keys function
@ 2015-06-23 18:08 Anshul Garg
  2015-06-23 18:57 ` Dmitry Torokhov
  0 siblings, 1 reply; 4+ messages in thread
From: Anshul Garg @ 2015-06-23 18:08 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input; +Cc: aksgarg1989, anshul.g

From: Anshul Garg <aksgarg1989@gmail.com>

input_dev_release_keys : Use for_each_set_bit instead
of testing every bit upto KEY_MAX as it is more clean
and more optimized.

input_estimate_events_per_packet : Use bitmap_weight
to get set bits count for EV_REL type instead of using
loop and also use for_each_set_bit for EV_ABS event for
more optimized code.

Signed-off-by: Anshul Garg <aksgarg1989@gmail.com>
---
 drivers/input/input.c |   28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index e0b7b8e..9459f8b 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -682,12 +682,9 @@ static void input_dev_release_keys(struct input_dev *dev)
 	int code;
 
 	if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
-		for (code = 0; code <= KEY_MAX; code++) {
-			if (is_event_supported(code, dev->keybit, KEY_MAX) &&
-			    __test_and_clear_bit(code, dev->key)) {
-				input_pass_event(dev, EV_KEY, code, 0);
-			}
-		}
+		for_each_set_bit(code, dev->keybit, KEY_MAX)
+			input_pass_event(dev, EV_KEY, code, 0);
+		memset(dev->keybit, 0, sizeof(dev->keybit));
 		input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
 	}
 }
@@ -1986,21 +1983,16 @@ static unsigned int input_estimate_events_per_packet(struct input_dev *dev)
 	events = mt_slots + 1; /* count SYN_MT_REPORT and SYN_REPORT */
 
 	if (test_bit(EV_ABS, dev->evbit)) {
-		for (i = 0; i < ABS_CNT; i++) {
-			if (test_bit(i, dev->absbit)) {
-				if (input_is_mt_axis(i))
-					events += mt_slots;
-				else
-					events++;
-			}
+		for_each_set_bit(i, dev->absbit, ABS_CNT) {
+			if (input_is_mt_axis(i))
+				events += mt_slots;
+			else
+				events++;
 		}
 	}
 
-	if (test_bit(EV_REL, dev->evbit)) {
-		for (i = 0; i < REL_CNT; i++)
-			if (test_bit(i, dev->relbit))
-				events++;
-	}
+	if (test_bit(EV_REL, dev->evbit))
+		events += bitmap_weight(dev->relbit, REL_CNT);
 
 	/* Make room for KEY and MSC events */
 	events += 7;
-- 
1.7.9.5


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Input :Optimize input_dev_release_keys function
  2015-06-23 18:08 [PATCH] Input :Optimize input_dev_release_keys function Anshul Garg
@ 2015-06-23 18:57 ` Dmitry Torokhov
  2015-06-23 19:45   ` Anshul Garg
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2015-06-23 18:57 UTC (permalink / raw)
  To: Anshul Garg; +Cc: linux-input, anshul.g

On Tue, Jun 23, 2015 at 11:08:23AM -0700, Anshul Garg wrote:
> From: Anshul Garg <aksgarg1989@gmail.com>
> 
> input_dev_release_keys : Use for_each_set_bit instead
> of testing every bit upto KEY_MAX as it is more clean
> and more optimized.
> 
> input_estimate_events_per_packet : Use bitmap_weight
> to get set bits count for EV_REL type instead of using
> loop and also use for_each_set_bit for EV_ABS event for
> more optimized code.
> 
> Signed-off-by: Anshul Garg <aksgarg1989@gmail.com>
> ---
>  drivers/input/input.c |   28 ++++++++++------------------
>  1 file changed, 10 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index e0b7b8e..9459f8b 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -682,12 +682,9 @@ static void input_dev_release_keys(struct input_dev *dev)
>  	int code;
>  
>  	if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
> -		for (code = 0; code <= KEY_MAX; code++) {
> -			if (is_event_supported(code, dev->keybit, KEY_MAX) &&
> -			    __test_and_clear_bit(code, dev->key)) {
> -				input_pass_event(dev, EV_KEY, code, 0);
> -			}
> -		}
> +		for_each_set_bit(code, dev->keybit, KEY_MAX)
> +			input_pass_event(dev, EV_KEY, code, 0);
> +		memset(dev->keybit, 0, sizeof(dev->keybit));

I do not think this will work, you are resetting wrong bitmap.
dev->keybit represents keys the device is capable of sending while
dev->key represents keys that are currently pressed. Once your code is
ran you should not get any more key events.

How was this tested?

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Input :Optimize input_dev_release_keys function
  2015-06-23 18:57 ` Dmitry Torokhov
@ 2015-06-23 19:45   ` Anshul Garg
  0 siblings, 0 replies; 4+ messages in thread
From: Anshul Garg @ 2015-06-23 19:45 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, anshul.g

Hello Mr. Dmitry,

Yes it was actually a typo.
I have tested the code with resetting "key" structure instead of "keybit".

I have resent the patch for the review.

Please check.


On Wed, Jun 24, 2015 at 12:27 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> On Tue, Jun 23, 2015 at 11:08:23AM -0700, Anshul Garg wrote:
>> From: Anshul Garg <aksgarg1989@gmail.com>
>>
>> input_dev_release_keys : Use for_each_set_bit instead
>> of testing every bit upto KEY_MAX as it is more clean
>> and more optimized.
>>
>> input_estimate_events_per_packet : Use bitmap_weight
>> to get set bits count for EV_REL type instead of using
>> loop and also use for_each_set_bit for EV_ABS event for
>> more optimized code.
>>
>> Signed-off-by: Anshul Garg <aksgarg1989@gmail.com>
>> ---
>>  drivers/input/input.c |   28 ++++++++++------------------
>>  1 file changed, 10 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/input/input.c b/drivers/input/input.c
>> index e0b7b8e..9459f8b 100644
>> --- a/drivers/input/input.c
>> +++ b/drivers/input/input.c
>> @@ -682,12 +682,9 @@ static void input_dev_release_keys(struct input_dev *dev)
>>       int code;
>>
>>       if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
>> -             for (code = 0; code <= KEY_MAX; code++) {
>> -                     if (is_event_supported(code, dev->keybit, KEY_MAX) &&
>> -                         __test_and_clear_bit(code, dev->key)) {
>> -                             input_pass_event(dev, EV_KEY, code, 0);
>> -                     }
>> -             }
>> +             for_each_set_bit(code, dev->keybit, KEY_MAX)
>> +                     input_pass_event(dev, EV_KEY, code, 0);
>> +             memset(dev->keybit, 0, sizeof(dev->keybit));
>
> I do not think this will work, you are resetting wrong bitmap.
> dev->keybit represents keys the device is capable of sending while
> dev->key represents keys that are currently pressed. Once your code is
> ran you should not get any more key events.
>
> How was this tested?
>
> Thanks.
>
> --
> Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] Input :Optimize input_dev_release_keys function
@ 2015-06-23 19:41 Anshul Garg
  0 siblings, 0 replies; 4+ messages in thread
From: Anshul Garg @ 2015-06-23 19:41 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input; +Cc: aksgarg1989, anshul.g

From: Anshul Garg <aksgarg1989@gmail.com>

input_dev_release_keys : Use for_each_set_bit instead
of testing every bit upto KEY_MAX as it is more clean
and more optimized.

input_estimate_events_per_packet : Use bitmap_weight
to get set bits count for EV_REL type instead of using
loop and also use for_each_set_bit for EV_ABS event for
more optimized code.

Signed-off-by: Anshul Garg <aksgarg1989@gmail.com>
---
 drivers/input/input.c |   28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index e0b7b8e..9459f8b 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -682,12 +682,9 @@ static void input_dev_release_keys(struct input_dev *dev)
 	int code;
 
 	if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
-		for (code = 0; code <= KEY_MAX; code++) {
-			if (is_event_supported(code, dev->keybit, KEY_MAX) &&
-			    __test_and_clear_bit(code, dev->key)) {
-				input_pass_event(dev, EV_KEY, code, 0);
-			}
-		}
+		for_each_set_bit(code, dev->keybit, KEY_MAX)
+			input_pass_event(dev, EV_KEY, code, 0);
+		memset(dev->key, 0, sizeof(dev->key));
 		input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
 	}
 }
@@ -1986,21 +1983,16 @@ static unsigned int input_estimate_events_per_packet(struct input_dev *dev)
 	events = mt_slots + 1; /* count SYN_MT_REPORT and SYN_REPORT */
 
 	if (test_bit(EV_ABS, dev->evbit)) {
-		for (i = 0; i < ABS_CNT; i++) {
-			if (test_bit(i, dev->absbit)) {
-				if (input_is_mt_axis(i))
-					events += mt_slots;
-				else
-					events++;
-			}
+		for_each_set_bit(i, dev->absbit, ABS_CNT) {
+			if (input_is_mt_axis(i))
+				events += mt_slots;
+			else
+				events++;
 		}
 	}
 
-	if (test_bit(EV_REL, dev->evbit)) {
-		for (i = 0; i < REL_CNT; i++)
-			if (test_bit(i, dev->relbit))
-				events++;
-	}
+	if (test_bit(EV_REL, dev->evbit))
+		events += bitmap_weight(dev->relbit, REL_CNT);
 
 	/* Make room for KEY and MSC events */
 	events += 7;
-- 
1.7.9.5


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-06-23 19:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-23 18:08 [PATCH] Input :Optimize input_dev_release_keys function Anshul Garg
2015-06-23 18:57 ` Dmitry Torokhov
2015-06-23 19:45   ` Anshul Garg
2015-06-23 19:41 Anshul Garg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.