Skip to contentSkip to conversation

System Inactivity Monitor v1.0

ANNOUNCE Alessandro Di Marco 9 participants 42 messages Jan 18, 2007 – Jan 27, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi all,

this is a new 2.6.20 module implementing a user inactivity trigger. Basically it acts as an event sniffer, issuing an ACPI event when no user activity is detected for more than a certain amount of time. This event can be successively grabbed and managed by an user-level daemon such as acpid, blanking the screen, dimming the lcd-panel light à la mac, etc...

For the interested guys I have included a bash configuration helper (called gentable) that covers the details.

Best,

Makefile +41 -0
diff -uN SIN/Makefile SIN.new/Makefile
@@ -0,0 +1,41 @@
+MODLPATH = kernel/drivers/char
+
+MODL = sinmod
+OBJS = sin.o procfs.o table.o input_enumerator.o acpi_enumerator.o
+
+SRCS := $(patsubst %.o,%.c,$(OBJS))
+HDRS := $(patsubst %.o,%.h,$(OBJS))
+CMDS := $(patsubst %.o,.%.o.cmd,$(OBJS))
+
+ifneq ($(KERNELRELEASE),)
+	EXTRA_CFLAGS := $(DEBUG)
+	obj-m := $(MODL).o
+	$(MODL)-objs := $(OBJS)
+else
+	KDIR := /lib/modules/$(shell uname -r)/build
+	PWD := $(shell pwd)
+
+all:	$(MODL).ko
+
+$(MODL).ko:	$(SRCS) $(HDRS)
+	@$(MAKE) -C $(KDIR) M=$(PWD) modules
+
+im:	$(MODL).ko
+	@sudo insmod $(MODL).ko
+
+rm:
+	@sudo rmmod $(MODL)
+
+rmf:
+	@sudo rmmod -f $(MODL)
+
+install:
+	@sudo $(MAKE) INSTALL_MOD_DIR=$(MODLPATH) -C $(KDIR) M=$(PWD) modules_install
+
+modules_install:
+	@$(MAKE) INSTALL_MOD_DIR=$(MODLPATH) -C $(KDIR) M=$(PWD) modules_install
+
+clean:
+	@$(MAKE) -C $(KDIR) M=$(PWD) clean
+	@rm -f Module.symvers
+endif
acpi_enumerator.c +114 -0

114 lines not on this page · raw message

acpi_enumerator.h +36 -0
diff -uN SIN/acpi_enumerator.h SIN.new/acpi_enumerator.h
@@ -0,0 +1,36 @@
+/*
+ *  Copyright (C) 2007 Alessandro Di Marco
+ */
+
+/*
+ *  This file is part of SIN.
+ *
+ *  SIN is free software; you can redistribute it and/or modify it under the
+ *  terms of the GNU General Public License as published by the Free Software
+ *  Foundation; version 2 of the License.
+ *
+ *  SIN is distributed in the hope that it will be useful, but WITHOUT ANY
+ *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ *  details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with SIN; if not, write to the Free Software Foundation, Inc., 51 Franklin
+ *  St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef ACPI_ENUMERATOR_H
+#define ACPI_ENUMERATOR_H
+
+#include <acpi/acpi_bus.h>
+
+struct acpi_handlers {
+	acpi_hardware_id hardware_id;
+};
+
+extern int get_handlers(void);
+extern char *get_hardware_id(int handle);
+extern int acpi_enum(char *page);
+extern void free_acpi_enum(void);
+
+#endif /* ACPI_ENUMERATOR_H */
gentable +170 -0

170 lines not on this page · raw message

input_enumerator.c +180 -0

180 lines not on this page · raw message

input_enumerator.h +45 -0

45 lines not on this page · raw message

procfs.c +215 -0

215 lines not on this page · raw message

procfs.h +35 -0
diff -uN SIN/procfs.h SIN.new/procfs.h
@@ -0,0 +1,35 @@
+/*
+ *  Copyright (C) 2007 Alessandro Di Marco
+ */
+
+/*
+ *  This file is part of Procfs.
+ *
+ *  Procfs is free software; you can redistribute it and/or modify it under the
+ *  terms of the GNU General Public License as published by the Free Software
+ *  Foundation; version 2 of the License.
+ *
+ *  Procfs is distributed in the hope that it will be useful, but WITHOUT ANY
+ *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ *  details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with Procfs; if not, write to the Free Software Foundation, Inc., 51
+ *  Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef PROCFS_H
+#define PROCFS_H
+
+#define RT_HELP "<debug>\n<pace>\n<N> <M>\n<input1> ... <inputN>\n<acpi>\n<reset>\n<special type> <special data>\n<counter1> <type1> <data1>\n...\n<counterM> <typeM> <dataM>\n"
+
+struct procfs_bs {
+	char *page;
+	int size;
+};
+
+extern int start_procfs(void);
+extern void stop_procfs(void);
+
+#endif /* PROCFS_H */
sin.c +190 -0

190 lines not on this page · raw message

sin.h +32 -0
diff -uN SIN/sin.h SIN.new/sin.h
@@ -0,0 +1,32 @@
+/*
+ *  Copyright (C) 2007 Alessandro Di Marco
+ */
+
+/*
+ *  This file is part of SIN.
+ *
+ *  SIN is free software; you can redistribute it and/or modify it under the
+ *  terms of the GNU General Public License as published by the Free Software
+ *  Foundation; version 2 of the License.
+ *
+ *  SIN is distributed in the hope that it will be useful, but WITHOUT ANY
+ *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ *  details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with SIN; if not, write to the Free Software Foundation, Inc., 51 Franklin
+ *  St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef SIN_H
+#define SIN_H
+
+#include <linux/input.h>
+
+#define MODULE_NAME "sin"
+
+extern int start_monitor(char *ids, struct input_device_id *idi, unsigned long pace);
+extern void stop_monitor(void);
+
+#endif /* SIN_H */
table.c +274 -0

274 lines not on this page · raw message

table.h +54 -0

54 lines not on this page · raw message

uniq.h +59 -0

59 lines not on this page · raw message

Signature · 2 lines
-- 
Man is the only animal that laughs and has a state legislature. - Samuel Butler
#1 lore raw
Quoted 7 lines · Alessandro Di Marco

Hi all,

this is a new 2.6.20 module implementing a user inactivity trigger. Basically it acts as an event sniffer, issuing an ACPI event when no user activity is detected for more than a certain amount of time. This event can be successively grabbed and managed by an user-level daemon such as acpid, blanking the screen, dimming the lcd-panel light à la mac, etc...

Hi,

why did you chose an ACPI event? I'd expect a uevent (which dbus captures etc) to be a more logical choice..

Greetings,
Arjan van de Ven

#2 lore raw

Arjan van de Ven <[email protected]> writes:

Quoted 7 lines · Alessandro Di Marco

Hi all,

this is a new 2.6.20 module implementing a user inactivity trigger. Basically it acts as an event sniffer, issuing an ACPI event when no user activity is detected for more than a certain amount of time. This event can be successively grabbed and managed by an user-level daemon such as acpid, blanking the screen, dimming the lcd-panel light à la mac, etc...

Hi,

why did you chose an ACPI event? I'd expect a uevent (which dbus captures etc) to be a more logical choice..

Laziness... :) Just an idea realized in a hurry to dim my laptop panel when it is in idle (I don't use X11, so no xscreensaver et simila.)

Anyway I can accommodate it, if someone of you thinks that it is interesting enough to be carried on the business.

The patch in attachment fixes some silly bugs of the previous version.

Regards,

procfs.c +26 -4
diff -uN old/procfs.c new/procfs.c
@@ -89,9 +89,19 @@
 	return err;
 }
 
+static int fake_write_proc(struct file *file, const __user char *ubuf,
+			   unsigned long count, void *data)
+{
+	void (*func)(void) = data;
+
+	func();
+	return count;
+}
+
 int start_procfs(void)
 {
-	struct proc_dir_entry *inputd, *acpid, *table, *ilink, *alink;
+	struct proc_dir_entry *inputd, *acpid,
+		*table, *interact, *ilink, *alink;
 
 	int err = -ENOMEM;
 
@@ -159,24 +169,35 @@
 	table->write_proc = write_proc;
 	table->owner = THIS_MODULE;
 
+	interact = create_proc_entry("interact", 0200, rootdir);
+	if (!interact) {
+		goto cleanout9;
+	}
+
+	interact->data = (void *) simulate_interaction;
+	interact->write_proc = fake_write_proc;
+	interact->owner = THIS_MODULE;
+
 	ilink = proc_symlink("sources", rootdir, "input");
 	if (!ilink) {
-		goto cleanout9;
+		goto cleanout10;
 	}
 
 	ilink->owner = THIS_MODULE;
 
 	alink = proc_symlink("destinations", rootdir, "acpi");
 	if (!alink) {
-		goto cleanout10;
+		goto cleanout11;
 	}
 
 	alink->owner = THIS_MODULE;
 
 	return 0;
 
-cleanout10:
+cleanout11:
 	remove_proc_entry("sources", rootdir);
+cleanout10:
+	remove_proc_entry("interact", rootdir);
 cleanout9:
 	remove_proc_entry("table", rootdir);
 cleanout8:
@@ -203,6 +224,7 @@
 {
 	remove_proc_entry("destinations", rootdir);
 	remove_proc_entry("sources", rootdir);
+	remove_proc_entry("interact", rootdir);
 	remove_proc_entry("table", rootdir);
 	remove_proc_entry("acpi", rootdir);
 	remove_proc_entry("input", rootdir);
sin.c +15 -5
diff -uN old/sin.c new/sin.c
@@ -34,7 +34,7 @@
 
 MODULE_ALIAS("blanker");
 
-MODULE_VERSION("1.0");
+MODULE_VERSION("1.2");
 
 static struct acpi_device *acpi_device;
 
@@ -49,13 +49,18 @@
 static DEFINE_MUTEX(runlock);
 static int running;
 
-static void event(struct input_handle *handle,
-		  unsigned int type, unsigned int code, int value)
+inline void signal_interaction(void)
 {
 	if (unlikely(test_and_clear_bit(0, &notify))) {
 		clear_bit(1, &notify);
 		occasionally_generate_event(acpi_device);
 	}
+}
+
+static void event(struct input_handle *handle,
+		  unsigned int type, unsigned int code, int value)
+{
+	signal_interaction();
 
 	atomic_inc(&interactions);
 }
@@ -166,8 +171,13 @@
 	if (running) {
 		shutdown = 1;
 		del_timer_sync(&timer);
+
 		input_unregister_handler(&ih);
 		kfree(ih.id_table);
+
+		signal_interaction();
+		cleanup_table();
+
 		running = 0;
 	}
 
@@ -176,14 +186,14 @@
 
 static int __init sih_init(void)
 {
-	printk("System Inactivity Notifier 1.0 - (c) Alessandro Di Marco <[email protected]>\n");
+	printk("System Inactivity Notifier 1.2 - (c) Alessandro Di Marco <[email protected]>\n");
 	return start_procfs();
 }
 
 static void __exit sih_exit(void)
 {
 	stop_procfs();
-	stop_monitor();
+	(void) stop_monitor();
 }
 
 module_init(sih_init);
sin.h +2 -0
diff -uN old/sin.h new/sin.h
@@ -26,6 +26,8 @@
 
 #define MODULE_NAME "sin"
 
+extern void signal_interaction(void);
+
 extern int start_monitor(char *ids, struct input_device_id *idi, unsigned long pace);
 extern void stop_monitor(void);
 
table.c +68 -47

238 lines not on this page · raw message

table.h +26 -0
diff -uN old/table.h new/table.h
@@ -31,6 +31,7 @@
 };
 
 struct table {
+	int debug;
 	unsigned long pace;
 	int dnum, rnum;
 	int *devices;
@@ -39,6 +40,28 @@
 	struct rule *rules;
 };
 
+static inline int tablecmp(struct table *l, struct table *r)
+{
+	if (l->debug != r->debug ||
+	    l->pace != r->pace ||
+	    l->dnum != r->dnum ||
+	    l->handle != r->handle ||
+	    l->rcounter != r->rcounter ||
+	    l->raction != r->raction) {
+		return 1;
+	}
+
+	if (memcmp(l->devices, r->devices, l->dnum * sizeof (int))) {
+		return 1;
+	}
+
+	if (memcmp(l->rules, r->rules, l->rnum * sizeof (struct rule))) {
+		return 1;
+	}
+
+	return 0;
+}
+
 #define TABLE_SIZE (sizeof (struct table) - 2 * sizeof (void *)	  \
 		    + rt.dnum * sizeof (int)			  \
 		    + rt.rnum * sizeof (struct rule))
@@ -48,7 +71,10 @@
 extern void occasionally_generate_event(struct acpi_device *acpi_device);
 extern void timely_generate_event(struct acpi_device *acpi_device, int interactions, unsigned long *notify);
 
+void simulate_interaction(void);
+
 extern int push_table(char *buf, unsigned long count);
 extern int pull_table(char **buf);
+extern void cleanup_table(void);
 
 #endif /* TABLE_H */
Signature · 3 lines
-- 
Ethics is not definable, is not implementable, because it is not conscious; it
involves not only our thinking, but also our feeling. - Valdemar W. Setzer
#3 lore raw
Quoted 3 lines · Alessandro Di Marco

The patch in attachment fixes some silly bugs of the previous version.

Regards,

Hi, attached is a patch for your gentable file, rewriting some of the user prompts to make them more readable.

Regards,
scott

gentable-new renamed from gentable +32 -32
@@ -31,9 +31,9 @@
 
 cat <<EOF
 
-SIN wakes up periodically and checks for user activity occurred in the
-meantime; this options lets you to specify how much frequently SIN should be
-woken-up. Its value is expressed in tenth of seconds.
+SIN wakes up periodically and checks whether user activity has occurred
+since it last ran; the next option lets you to specify how frequently
+SIN should wake up. Its value is expressed in tenth of seconds.
 
 EOF
 
@@ -45,9 +45,9 @@
 
 cat <<EOF
 
-Asleep or not, SIN constantly monitors the input devices searching for user
-activity. This option lets you choose which device have to be monitored. At
-least one device is needed and please avoid the duplicates.
+Asleep or not, SIN constantly monitors the input devices watching for user
+activity. The next option lets you choose which device have to be monitored.
+You must specify at least one device and must not specify duplicates.
 
 EOF
 
@@ -65,7 +65,7 @@
 
 cat <<EOF
 
-SIN produces ACPI events depending on the user activity. To do this you have to
+SIN produces ACPI events depending on the user activity. You must
 specify a suitable handler that will be used as originator.
 
 EOF
@@ -74,7 +74,7 @@
 cat /proc/sin/acpi
 
 echo
-input "Please digit the corresponding number" handle
+input "Please enter the number corresponding to the handler" handle
 
 if [ -z "${handle}" ]; then
     handle="0"
@@ -82,19 +82,19 @@
 
 cat <<EOF
 
-SIN produces events in base to rules. Each rule is a triple composed by a
-"counter", a "type" and a "data". Once awaken, a global counter is increased if
-SIN detects no user activity and reset to zero, otherwise. When this global
-counter reaches the value specified in the counter field of a rule, an event is
-generated with the corresponding "type" and "data". Clearly, different rules
-should have different "type" and "data" fields to convey different signals to
-the user space daemon.
+SIN produces events based on rules. Each rule is a triple composed by a
+"counter", a "type", and a "data" value. When SIN awakens, a global counter
+is increased if SIN detects no user activity and reset to zero, otherwise.
+When this global counter reaches the value specified in the counter field
+of a rule, an event is generated with the corresponding "type" and "data".
+Different rules should have different "type" and "data" fields to convey
+different signals to the user space daemon.
 
 For example, the rule "60 1 19" produces the ACPI event "XXXX 00000001
-00000019" right after one minute of user inactivity (assuming pace=10.)
+00000019" when SIN recognizes one minute of user inactivity (assuming pace=10.)
 
-Please specify each rule as a space-separated triple; to finish just press
-enter.
+Please specify each rule as a space-separated triple on a separate line;
+when finished, just press enter.
 
 EOF
 
@@ -114,9 +114,9 @@
 
 cat <<EOF
 
-A special event has been provided to better help those of us who wanna use SIN
+A special event has been provided to simplify using SIN
 as a screen-blanker. It will be generated as soon as some user activity is
-detected, but only after one or more rule have been triggered.
+detected, but only after one or more rules have been triggered.
 
 EOF
 
@@ -128,16 +128,16 @@
 
 cat <<EOF
 
-Usually a rule-list terminates with dead-end actions such as suspend or
-hibernate, requiring the user interaction to wake-up the system. Unfortunately
-this activity occurs when SIN, as well as the kernel, are not ready to capture
-these events yet. As a consequence, no special event will ever be generated and
+Often an SIN event results in suspending or hibernating the system,
+hibernate, requiring user interaction to wake-up the system. Unfortunately
+that interaction occurs when SIN, as well as the kernel, cannot capture
+it. As a consequence, no event will ever be generated and
 the system will remain in the state associated with the next-to-last rule
-(e.g. blanked screen, wireless powered off, etc.) In such cases this field
-forces the special event generation, resetting simultaneously the global
-counter to an arbitrary value, so to reinstate the rule-list evaluation to the
-beginning. Possible value ranges are described below, where N is the maximum
-counter in the rule list:
+(e.g. blanked screen, wireless powered off, etc.). The next option
+allows you to request a special event, resetting the global
+counter to an arbitrary value, so to restart the rule-list evaluation.
+Possible value ranges are described below, where N is the maximum
+counter in the current rule list:
 
     [0, N]    => reset the global counter to the specified value
     otherwise => do nothing, the global counter goes on and on and on...
@@ -163,8 +163,8 @@
 # modprobe sinmod
 # echo $1 >/proc/sin/table
 
-An "Invalid argument" error signals a mismatch in the table file, usually due
-to wrong acpi or input device specified. In these cases restart from scratch
-double checking your answers. Have fun!
+An "Invalid argument" error indicates a mismatch in the table file, usually
+due to specifying an invalid acpi or input device. In that case, restart from
+scratch, double checking your inputs. Have fun!
 
 EOF
#6 lore raw
In reply to Alessandro Di Marco
Quoted 7 lines · Alessandro Di Marco

Hi all,

this is a new 2.6.20 module implementing a user inactivity trigger. Basically it acts as an event sniffer, issuing an ACPI event when no user activity is detected for more than a certain amount of time. This event can be successively grabbed and managed by an user-level daemon such as acpid, blanking the screen, dimming the lcd-panel light à la mac, etc...

Any idea how much power this saves? And for the vast rest of us who do run X, this seems to parallel the work of a well-tuned screensaver.

Signature · 3 lines
bill davidsen <[email protected]>
  CTO TMR Associates, Inc
  Doing interesting things with small computers since 1979
#4 lore raw
In reply to Scott Preece
Quoted 2 lines · Scott Preece

Hi, attached is a patch for your gentable file, rewriting some of the user prompts to make them more readable.

I still don't get why this is called "SIN" in the Kconfig and code texts though the acronym for System Inactivity Monitor would be "SIM".

	-`J'
#5 lore raw
Quoted 7 lines · Jan Engelhardt
Quoted 2 lines · Scott Preece

Hi, attached is a patch for your gentable file, rewriting some of the user prompts to make them more readable.

I still don't get why this is called "SIN" in the Kconfig and code texts though the acronym for System Inactivity Monitor would be "SIM".

---

The code calls it "System Inactivity Notifier".

scott

#7 lore raw
In reply to Bill Davidsen

Bill Davidsen <[email protected]> writes:

Quoted 7 lines · Alessandro Di Marco

Hi all,

this is a new 2.6.20 module implementing a user inactivity trigger. Basically it acts as an event sniffer, issuing an ACPI event when no user activity is detected for more than a certain amount of time. This event can be successively grabbed and managed by an user-level daemon such as acpid, blanking the screen, dimming the lcd-panel light à la mac, etc...

Any idea how much power this saves? And for the vast rest of us who do run X, this seems to parallel the work of a well-tuned screensaver.

This is just a notifier; to make it work as a screensaver you'll have to rely on some external programs. Personally I use smartdimmer to dim my vaio panel.

Obviously you can keep your toaster flying, if you like, simply calling the flying-toaster module instead of smartdimmer. Anyway I would use the latter on battery. ;-)

Best,

Signature · 5 lines
"What made the deepest impression upon you?" inquired a friend one day of
Lincoln, "when you stood in the presence of the Falls of Niagara, the greatest
of natural wonders?" ---- "The thing that stuck me most forcibly when I saw the
Falls," Lincoln responded with the characteristic deliberation, "was where in
the world did all that water come from?" - Author Unknown
#8 lore raw
In reply to Alessandro Di Marco

HiQ

Quoted 5 lines

this is a new 2.6.20 module implementing a user inactivity trigger. Basically it acts as an event sniffer, issuing an ACPI event when no user activity is detected for more than a certain amount of time. This event can be successively grabbed and managed by an user-level daemon such as acpid, blanking the screen, dimming the lcd-panel light ? la mac, etc...

While functionality is extremely interesting.... does it really have to be in kernel?

gentable line 30

Quoted 4 lines
gentable +4 -0
+if [ ! -d "/proc/sin" ]; then
+    echo "/proc/sin not found, has sinmod been loaded?"
+    exit
+fi

No new /proc files, please.

gentable line 36

Quoted 5 lines
gentable +5 -0
+cat <<EOF
+
+SIN wakes up periodically and checks for user activity occurred in the
+meantime; this options lets you to specify how much frequently SIN should be
+woken-up. Its value is expressed in tenth of seconds.

Heh. We'll waste power trying to save it. If you have to hook it into kernel, can you at least do it properly?

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#9 lore raw
Quoted 9 lines · Pavel Machek
Quoted 6 lines

this is a new 2.6.20 module implementing a user inactivity trigger. Basically it acts as an event sniffer, issuing an ACPI event when no user activity is detected for more than a certain amount of time. This event can be successively grabbed and managed by an user-level daemon such as acpid, blanking the screen, dimming the lcd-panel light ? la mac, etc...

While functionality is extremely interesting.... does it really have to be in kernel?

I think so. While the X server grabs off any keyboard and mouse activity on its own, there is no such thing for the [read "all"] console[s]. Mouse movement (e.g. GPM) is actually implemented in the kernel, and screen blanking (the one controlled with "\e[9;x]") is too.

	-`J'
#11 lore raw
In reply to Pavel Machek

Review

Quoted 4 lines · Pavel Machek
(quoted diff) +4 -0
+if [ ! -d "/proc/sin" ]; then
+    echo "/proc/sin not found, has sinmod been loaded?"
+    exit
+fi

No new /proc files, please.

This was merely a prototype realized in a hurry, not a production driver. Really, I did't think it could be interesting for anybody.

Would be /sys ok?

Review

Quoted 5 lines
(quoted diff) +5 -0
+cat <<EOF
+
+SIN wakes up periodically and checks for user activity occurred in the
+meantime; this options lets you to specify how much frequently SIN should be
+woken-up. Its value is expressed in tenth of seconds.

Heh. We'll waste power trying to save it.

Well, not just a power saver. For example I use SIN to auto-logoff my bash session as well (detaching the screen session.)

If you have to hook it into kernel, can you at least do it properly?

Of course. You can find attached a patch fixing this. Now SIN wakes up just when it expects to do something: if in the meantime the user interacts with the system, SIN simply recalculates the next wake-up time on the basis of the last user's activity date and goes to sleep again.

Best,

---
 gentable |   72 +++++++++++++---------------------
 procfs.c |    2 +-
 sin.c    |   68 ++++++++++++++++++++------------
 sin.h    |   36 ++++++++++++++++-
 table.c  |  132 ++++++++++++++++++++++++++++----------------------------------
 table.h  |   21 +++++-----
 6 files changed, 176 insertions(+), 155 deletions(-)
gentable +28 -44
index 44b4f77..3a322df 100755
@@ -31,23 +31,9 @@ fi
 
 cat <<EOF
 
-SIN wakes up periodically and checks whether user activity has occurred
-since it last ran; the next option lets you to specify how frequently
-SIN should wake up. Its value is expressed in tenth of seconds.
-
-EOF
-
-input "Pace ticks?" pace
-
-if [ -z "${pace}" ]; then
-    pace="10"
-fi
-
-cat <<EOF
-
-Asleep or not, SIN constantly monitors the input devices watching for user
-activity. The next option lets you choose which device have to be monitored.
-You must specify at least one device and must not specify duplicates.
+SIN constantly monitors the input devices watching for user activity. This
+option lets you choose which device have to be monitored. You must specify at
+least one device and must not specify duplicates.
 
 EOF
 
@@ -65,8 +51,8 @@ devices=(${devs})
 
 cat <<EOF
 
-SIN produces ACPI events depending on the user activity. You must
-specify a suitable handler that will be used as originator.
+SIN produces ACPI events depending on the user activity. You must specify a
+suitable handler that will be used as originator.
 
 EOF
 
@@ -83,18 +69,17 @@ fi
 cat <<EOF
 
 SIN produces events based on rules. Each rule is a triple composed by a
-"counter", a "type", and a "data" value. When SIN awakens, a global counter
-is increased if SIN detects no user activity and reset to zero, otherwise.
-When this global counter reaches the value specified in the counter field
-of a rule, an event is generated with the corresponding "type" and "data".
-Different rules should have different "type" and "data" fields to convey
-different signals to the user space daemon.
+"target", a "type", and a "data" value. The "target" field is a timeout in
+tenth of seconds specifying the minimum period of user inactivity needed to
+trigger the rule. When a rule triggers, an event is generated with the
+corresponding "type" and "data".  Different rules should have different "type"
+and "data" fields to convey different signals to the user space daemon.
 
-For example, the rule "60 1 19" produces the ACPI event "XXXX 00000001
-00000019" when SIN recognizes one minute of user inactivity (assuming pace=10.)
+For example, the rule "600 1 19" produces the ACPI event "XXXX 00000001
+00000019" when SIN recognizes one minute of user inactivity.
 
-Please specify each rule as a space-separated triple on a separate line;
-when finished, just press enter.
+Please specify each rule as a space-separated triple on a separate line; when
+finished, just press enter.
 
 EOF
 
@@ -114,9 +99,9 @@ fi
 
 cat <<EOF
 
-A special event has been provided to simplify using SIN
-as a screen-blanker. It will be generated as soon as some user activity is
-detected, but only after one or more rules have been triggered.
+A special event has been provided to simplify using SIN as a screen-blanker. It
+will be generated as soon as some user activity is detected, but only after one
+or more rules have been triggered.
 
 EOF
 
@@ -128,15 +113,14 @@ fi
 
 cat <<EOF
 
-Often an SIN event results in suspending or hibernating the system,
-hibernate, requiring user interaction to wake-up the system. Unfortunately
-that interaction occurs when SIN, as well as the kernel, cannot capture
-it. As a consequence, no event will ever be generated and
-the system will remain in the state associated with the next-to-last rule
-(e.g. blanked screen, wireless powered off, etc.). The next option
-allows you to request a special event, resetting the global
-counter to an arbitrary value, so to restart the rule-list evaluation.
-Possible value ranges are described below, where N is the maximum
+Often an SIN event results in suspending or hibernating the system, hibernate,
+requiring user interaction to wake-up the system. Unfortunately that
+interaction occurs when SIN, as well as the kernel, cannot capture it. As a
+consequence, no event will ever be generated and the system will remain in the
+state associated with the next-to-last rule (e.g. blanked screen, wireless
+powered off, etc.). The next option allows you to request a special event,
+resetting the global counter to an arbitrary value, so to restart the rule-list
+evaluation.  Possible value ranges are described below, where N is the maximum
 counter in the current rule list:
 
     [0, N]    => reset the global counter to the specified value
@@ -150,7 +134,7 @@ if [ -z "${reset}" ]; then
     reset="-1"
 fi
 
-echo -e "0\n${pace}\n${#devices[@]} ${#rules[@]}\n${devices[@]}\n${handle}\n${reset}\n${resume}" > $1
+echo -e "0\n${#devices[@]} ${#rules[@]}\n${devices[@]}\n${handle}\n${reset}\n${resume}" > $1
 
 for (( i = 0; ${i}<${#rules[@]}; i++ )); do
     echo "${rules[${i}]}" >> $1
@@ -163,8 +147,8 @@ All done. Now you can try your newly generated table as follows:
 # modprobe sinmod
 # echo $1 >/proc/sin/table
 
-An "Invalid argument" error indicates a mismatch in the table file, usually
-due to specifying an invalid acpi or input device. In that case, restart from
+An "Invalid argument" error indicates a mismatch in the table file, usually due
+to specifying an invalid acpi or input device. In that case, restart from
 scratch, double checking your inputs. Have fun!
 
 EOF
procfs.c +1 -1
index 4424645..5929f90 100644
@@ -174,7 +174,7 @@ int start_procfs(void)
 		goto cleanout9;
 	}
 
-	interact->data = (void *) simulate_interaction;
+	interact->data = (void *) simulate_event;
 	interact->write_proc = fake_write_proc;
 	interact->owner = THIS_MODULE;
 
sin.c +42 -26

131 lines not on this page · raw message

sin.h +35 -1
index 249021c..95161b2 100644
@@ -26,9 +26,43 @@
 
 #define MODULE_NAME "sin"
 
+#define RULE_TRIG 0
+#define RULE_WRAP 1
+#define RULE_LOCK 2
+#define RULE_MARK 3
+
+struct user_activity {
+	spinlock_t lock;
+	unsigned long last;
+};
+
+static inline unsigned long register_activity(struct user_activity *uact)
+{
+	unsigned long last;
+
+	spin_lock(&uact->lock);
+	last = uact->last = jiffies;
+	spin_unlock(&uact->lock);
+
+	return last;
+}
+
+static inline unsigned long last_activity(struct user_activity *uact)
+{
+	unsigned long last;
+
+	spin_lock(&uact->lock);
+	last = uact->last;
+	spin_unlock(&uact->lock);
+
+	return last;
+}
+
+extern unsigned long simulate_activity(void);
 extern void signal_interaction(void);
+extern void simulate_event(void);
 
-extern int start_monitor(char *ids, struct input_device_id *idi, unsigned long pace);
+extern int start_monitor(char *ids, struct input_device_id *idi);
 extern void stop_monitor(void);
 
 #endif /* SIN_H */
table.c +59 -73

228 lines not on this page · raw message

table.h +11 -10
index 413b8eb..71b19d2 100644
@@ -25,29 +25,32 @@
 #include <acpi/acpi_bus.h>
 
 struct rule {
-	int counter;
+	unsigned long target; /* jiffies */
 	int type;
 	int data;
 };
 
 struct table {
 	int debug;
-	unsigned long pace;
 	int dnum, rnum;
 	int *devices;
 	int handle;
-	int rcounter, raction;
+	int rwrap;
 	struct rule *rules;
 };
 
+#define printd(fmt...)				\
+	if (unlikely(rt.debug)) {		\
+		printk(fmt);			\
+	}
+
 static inline int tablecmp(struct table *l, struct table *r)
 {
 	if (l->debug != r->debug ||
-	    l->pace != r->pace ||
 	    l->dnum != r->dnum ||
+	    l->rnum != r->rnum ||
 	    l->handle != r->handle ||
-	    l->rcounter != r->rcounter ||
-	    l->raction != r->raction) {
+	    l->rwrap != r->rwrap) {
 		return 1;
 	}
 
@@ -66,12 +69,10 @@ static inline int tablecmp(struct table *l, struct table *r)
 		    + rt.dnum * sizeof (int)			  \
 		    + rt.rnum * sizeof (struct rule))
 
-#define TABLE_BUFFER_SIZE (9 + rt.dnum + rt.rnum * 3 + (TABLE_SIZE << 3) / 3)
+#define TABLE_BUFFER_SIZE (8 + rt.dnum + rt.rnum * 3 + (TABLE_SIZE << 3) / 3)
 
 extern void occasionally_generate_event(struct acpi_device *acpi_device);
-extern void timely_generate_event(struct acpi_device *acpi_device, int interactions, unsigned long *notify);
-
-void simulate_interaction(void);
+extern unsigned long timely_generate_event(struct acpi_device *acpi_device, unsigned long last, unsigned long *notify);
 
 extern int push_table(char *buf, unsigned long count);
 extern int pull_table(char **buf);

--
1.4.4.4

Signature · 3 lines
-- 
Of one thing I am certain, the body is not the measure of healing - peace is
the measure. - George Melton
#10 lore raw
In reply to Jan Engelhardt

Hi!

Quoted 5 lines
Quoted 2 lines

While functionality is extremely interesting.... does it really have to be in kernel?

I think so. While the X server grabs off any keyboard and mouse activity on its own, there is no such thing for the [read "all"] console[s].

I believe input subsystem can already do that.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#12 lore raw
In reply to Alessandro Di Marco

Hi!

Quoted 11 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+if [ ! -d "/proc/sin" ]; then
+    echo "/proc/sin not found, has sinmod been loaded?"
+    exit
+fi

No new /proc files, please.

This was merely a prototype realized in a hurry, not a production driver. Really, I did't think it could be interesting for anybody.

Would be /sys ok?

If it has to be in kernel, /sys/power is probably ok. But I still believe it can be out.

Yes, I believe it is interesting: on modern machine, you want to control keyboard illumination, lower backlight after short inactivity, turn screen off after longer one, etc...

Quoted 4 lines

Heh. We'll waste power trying to save it.

Well, not just a power saver. For example I use SIN to auto-logoff my bash session as well (detaching the screen session.)

Ok, ok :-).

Quoted 6 lines

If you have to hook it into kernel, can you at least do it properly?

Of course. You can find attached a patch fixing this. Now SIN wakes up just when it expects to do something: if in the meantime the user interacts with the system, SIN simply recalculates the next wake-up time on the basis of the last user's activity date and goes to sleep again.

Good.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#13 lore raw

Pavel Machek <[email protected]> writes:

Hi!

Quoted 11 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+if [ ! -d "/proc/sin" ]; then
+    echo "/proc/sin not found, has sinmod been loaded?"
+    exit
+fi

No new /proc files, please.

This was merely a prototype realized in a hurry, not a production driver. Really, I did't think it could be interesting for anybody.

Would be /sys ok?

If it has to be in kernel, /sys/power is probably ok.

Doh! The attached patch introduces /sys/class/misc (along with some bug-fixes.) In case I'll change it again.

Ah, there is still a time-warp bug pending. In practice I have to turn off the timer just before suspending, hibernating, etc or it will give you hell on the next system resume...

But I still believe it can be out.

Do you believe it could be a user-space daemon or what?

Best,

Quoted 1 line

From f97e411d29d5771e3ac3d9c8e8aa4ad3ae0a27e2 Mon Sep 17 00:00:00 2001

From: Alessandro Di Marco <[email protected]>
Date: Tue, 23 Jan 2007 02:21:07 +0100
Subject: [PATCH] Added sysfs support; various timer bugfix, but time warp bug is still with us.

---
 Makefile           |    2 +-
 acpi_enumerator.c  |   27 +++++++--
 acpi_enumerator.h  |    5 +-
 gentable           |   17 +++---
 input_enumerator.c |   28 ++++++++--
 input_enumerator.h |    4 +-
 procfs.c           |  157 ++++++++++++++++++++--------------------------------
 procfs.h           |   12 ++--
 sin.c              |   86 ++++++++++++++++++++++++++--
 sin.h              |    9 ++-
 sysfs.c            |  146 ++++++++++++++++++++++++++++++++++++++++++++++++
 sysfs.h            |   28 +++++++++
 table.c            |  128 ++++++++++++++++++++++++++++--------------
 table.h            |    8 ++-
 14 files changed, 476 insertions(+), 181 deletions(-)
Makefile +1 -1
index a72fb3c..d45fa58 100644
@@ -1,7 +1,7 @@
 MODLPATH = kernel/drivers/char
 
 MODL = sinmod
-OBJS = sin.o procfs.o table.o input_enumerator.o acpi_enumerator.o
+OBJS = sin.o procfs.o sysfs.o table.o input_enumerator.o acpi_enumerator.o
 
 SRCS := $(patsubst %.o,%.c,$(OBJS))
 HDRS := $(patsubst %.o,%.h,$(OBJS))
acpi_enumerator.c +22 -5
index c9033e5..c25a268 100644
@@ -35,6 +35,12 @@ int get_handlers(void)
 	return ahsize;
 }
 
+size_t get_handlers_desc(char **buf)
+{
+	*buf = page;
+	return size;
+}
+
 char *get_hardware_id(int handle)
 {
 	return ah[handle].hardware_id;
@@ -75,11 +81,15 @@ static int acpi_show(struct acpi_device *device, struct acpi_driver *driver)
 	return -ENOENT;
 }
 
-int acpi_enum(char *buf)
+int acpi_enum(void)
 {
 	struct acpi_driver ad;
+	int err = -ENOMEM;
 
-	page = buf;
+	page = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!page) {
+		goto out;
+	}
 
 	ad.ops.match = acpi_show;
 	(void) acpi_bus_register_driver(&ad);
@@ -87,7 +97,8 @@ int acpi_enum(char *buf)
 
 	if (!ahsize) {
 		printk(KERN_NOTICE "no acpi handlers found\n");
-		return -ENODEV;
+		err = -ENODEV;
+		goto cleanout;
 	}
 
 	ah = kmalloc(ahsize * sizeof (struct acpi_handlers), GFP_KERNEL);
@@ -95,14 +106,19 @@ int acpi_enum(char *buf)
 	ahsize = 0;
 
 	if (!ah) {
-		return -ENOMEM;
+		goto cleanout;
 	}
 
 	ad.ops.match = acpi_store;
 	(void) acpi_bus_register_driver(&ad);
 	acpi_bus_unregister_driver(&ad);
 
-	return size;
+	return 0;
+
+cleanout:
+	kfree(page);
+out:
+	return err;
 }
 
 void free_acpi_enum(void)
@@ -110,5 +126,6 @@ void free_acpi_enum(void)
 	if (ahsize) {
 		ahsize = 0;
 		kfree(ah);
+		kfree(page);
 	}
 }
acpi_enumerator.h +4 -1
index 998db65..0b75a09 100644
@@ -29,8 +29,11 @@ struct acpi_handlers {
 };
 
 extern int get_handlers(void);
+extern size_t get_handlers_desc(char **buf);
+
 extern char *get_hardware_id(int handle);
-extern int acpi_enum(char *page);
+
+extern int acpi_enum(void);
 extern void free_acpi_enum(void);
 
 #endif /* ACPI_ENUMERATOR_H */
gentable +8 -9
index 3a322df..49af1f4 100755
@@ -119,22 +119,21 @@ interaction occurs when SIN, as well as the kernel, cannot capture it. As a
 consequence, no event will ever be generated and the system will remain in the
 state associated with the next-to-last rule (e.g. blanked screen, wireless
 powered off, etc.). The next option allows you to request a special event,
-resetting the global counter to an arbitrary value, so to restart the rule-list
-evaluation.  Possible value ranges are described below, where N is the maximum
-counter in the current rule list:
+restarting the rule-list evaluation from an arbitrary position.  Possible value
+ranges are described below, where N is the rule-list size:
 
-    [0, N]    => reset the global counter to the specified value
-    otherwise => do nothing, the global counter goes on and on and on...
+    [0, N - 1]	=> jump to the given rule
+    N		=> go to sleep and wait for user interaction
 
 EOF
 
-input "Reset value?" reset
+input "Wrap value?" wrap
 
-if [ -z "${reset}" ]; then
-    reset="-1"
+if [ -z "${wrap}" ]; then
+    wrap="-1"
 fi
 
-echo -e "0\n${#devices[@]} ${#rules[@]}\n${devices[@]}\n${handle}\n${reset}\n${resume}" > $1
+echo -e "0\n${#devices[@]} ${#rules[@]}\n${devices[@]}\n${handle}\n${wrap}\n${resume}" > $1
 
 for (( i = 0; ${i}<${#rules[@]}; i++ )); do
     echo "${rules[${i}]}" >> $1
input_enumerator.c +23 -5
index b046cb4..6fd7827 100644
@@ -35,6 +35,12 @@ int get_devices(void)
 	return idsize;
 }
 
+size_t get_devices_desc(char **buf)
+{
+	*buf = page;
+	return size;
+}
+
 void fill_input_device(struct input_device_id *idi, int device)
 {
 	idi->flags = MATCH_MODEL;
@@ -135,8 +141,10 @@ skip:
 	return NULL;
 }
 
-int input_enum(char *buf)
+int input_enum(void)
 {
+	int err = -ENOMEM;
+
 	const struct input_device_id idi[] = {
 		{ .driver_info = 1 },	/* matches all devices */
 		{ },
@@ -147,14 +155,18 @@ int input_enum(char *buf)
 		.id_table =	idi,
 	};
 
-	page = buf;
+	page = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!page) {
+		goto out;
+	}
 
 	ih.connect = input_show;
 	(void) input_register_handler(&ih);
 
 	if (!idsize) {
 		printk(KERN_NOTICE "no input devices found\n");
-		return -ENODEV;
+		err = -ENODEV;
+		goto cleanout;
 	}
 
 	id = kmalloc(idsize * sizeof (struct input_devices), GFP_KERNEL);
@@ -162,13 +174,18 @@ int input_enum(char *buf)
 	idsize = 0;
 
 	if (!id) {
-		return -ENOMEM;
+		goto cleanout;
 	}
 
 	ih.connect = input_store;
 	(void) input_register_handler(&ih);
 
-	return size;
+	return 0;
+
+cleanout:
+	kfree(page);
+out:
+	return err;
 }
 
 void free_input_enum(void)
@@ -176,5 +193,6 @@ void free_input_enum(void)
 	if (idsize) {
 		idsize = 0;
 		kfree(id);
+		kfree(page);
 	}
 }
input_enumerator.h +3 -1
index 0e87207..45ffe93 100644
@@ -37,9 +37,11 @@ struct input_devices {
 		     |INPUT_DEVICE_ID_MATCH_VERSION)
 
 extern int get_devices(void);
+extern size_t get_devices_desc(char **buf);
+
 extern void fill_input_device(struct input_device_id *idi, int i);
 
-extern int input_enum(char *page);
+extern int input_enum(void);
 extern void free_input_enum(void);
 
 #endif /* INPUT_ENUMERATOR_H */
procfs.c +61 -96

241 lines not on this page · raw message

procfs.h +5 -7
index 890d1ce..ea164be 100644
@@ -3,27 +3,25 @@
  */
 
 /*
- *  This file is part of Procfs.
+ *  This file is part of SIN.
  *
- *  Procfs is free software; you can redistribute it and/or modify it under the
+ *  SIN is free software; you can redistribute it and/or modify it under the
  *  terms of the GNU General Public License as published by the Free Software
  *  Foundation; version 2 of the License.
  *
- *  Procfs is distributed in the hope that it will be useful, but WITHOUT ANY
+ *  SIN is distributed in the hope that it will be useful, but WITHOUT ANY
  *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  *  details.
  *
  *  You should have received a copy of the GNU General Public License along
- *  with Procfs; if not, write to the Free Software Foundation, Inc., 51
- *  Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *  with SIN; if not, write to the Free Software Foundation, Inc., 51 Franklin
+ *  St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #ifndef PROCFS_H
 #define PROCFS_H
 
-#define RT_HELP "<debug>\n<pace>\n<N> <M>\n<input1> ... <inputN>\n<acpi>\n<reset>\n<special type> <special data>\n<counter1> <type1> <data1>\n...\n<counterM> <typeM> <dataM>\n"
-
 struct procfs_bs {
 	char *page;
 	int size;
sin.c +80 -6

128 lines not on this page · raw message

sin.h +5 -4
index 95161b2..1ef52d2 100644
@@ -26,10 +26,11 @@
 
 #define MODULE_NAME "sin"
 
-#define RULE_TRIG 0
-#define RULE_WRAP 1
-#define RULE_LOCK 2
-#define RULE_MARK 3
+#define RULE_TRIG 0 /* a rule has been triggered */
+#define RULE_WRAP 1 /* rule-evaluation has been restarted */
+#define RULE_LOCK 2 /* evaluating rule-list, don't mess */
+#define RULE_MARK 3 /* event seen while evaluating rule-list */
+#define RULE_OVER 4 /* no more rules, please disconnect timer */
 
 struct user_activity {
 	spinlock_t lock;
sysfs.c new file +146 -0

146 lines not on this page · raw message

sysfs.h new file +28 -0
new file mode 100644
index 0000000..465258a
@@ -0,0 +1,28 @@
+/*
+ *  Copyright (C) 2007 Alessandro Di Marco
+ */
+
+/*
+ *  This file is part of SIN.
+ *
+ *  SIN is free software; you can redistribute it and/or modify it under the
+ *  terms of the GNU General Public License as published by the Free Software
+ *  Foundation; version 2 of the License.
+ *
+ *  SIN is distributed in the hope that it will be useful, but WITHOUT ANY
+ *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ *  details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with SIN; if not, write to the Free Software Foundation, Inc., 51 Franklin
+ *  St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef SYSFS_H
+#define SYSFS_H
+
+extern int start_sysfs(struct device *dev);
+extern void stop_sysfs(void);
+
+#endif /* SYSFS_H */
table.c +85 -43

200 lines not on this page · raw message

table.h +5 -3
index 71b19d2..fd6b91f 100644
@@ -65,17 +65,19 @@ static inline int tablecmp(struct table *l, struct table *r)
 	return 0;
 }
 
+#define TABLE_HELP "<debug>\n<N> <M>\n<input1> ... <inputN>\n<acpi>\n<wrap>\n<special type> <special data>\n<trigger1> <type1> <data1>\n...\n<triggerM> <typeM> <dataM>\n"
+
 #define TABLE_SIZE (sizeof (struct table) - 2 * sizeof (void *)	  \
 		    + rt.dnum * sizeof (int)			  \
 		    + rt.rnum * sizeof (struct rule))
 
 #define TABLE_BUFFER_SIZE (8 + rt.dnum + rt.rnum * 3 + (TABLE_SIZE << 3) / 3)
 
-extern void occasionally_generate_event(struct acpi_device *acpi_device);
+extern unsigned long occasionally_generate_event(struct acpi_device *acpi_device, unsigned long last);
 extern unsigned long timely_generate_event(struct acpi_device *acpi_device, unsigned long last, unsigned long *notify);
 
-extern int push_table(char *buf, unsigned long count);
-extern int pull_table(char **buf);
+extern int push_table(const char *buf, unsigned long count);
+extern size_t pull_table(char **buf);
 extern void cleanup_table(void);
 
 #endif /* TABLE_H */
Signature · 1 line
1.4.4.4

--
As you grow older, you'll find the only things you regret are the things you didn't do. - Zachary Scott

#14 lore raw

Hi1

Quoted 10 lines
Quoted 10 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+if [ ! -d "/proc/sin" ]; then
+    echo "/proc/sin not found, has sinmod been loaded?"
+    exit
+fi

No new /proc files, please.

This was merely a prototype realized in a hurry, not a production driver. Really, I did't think it could be interesting for anybody.

Quoted 6 lines
Quoted 1 line

Would be /sys ok?

If it has to be in kernel, /sys/power is probably ok.

Doh! The attached patch introduces /sys/class/misc (along with some bug-fixes.) In case I'll change it again.

No, just leave it where it is. Maybe better location will be invented, but mine idea was just first shot.

Quoted 3 lines

But I still believe it can be out.

Do you believe it could be a user-space daemon or what?

Yes, what prevents userspace daemon watching /dev/input/event* to provide this functionality?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#15 lore raw
Quoted 3 lines · Pavel Machek

But I still believe it can be out.

Do you believe it could be a user-space daemon or what?

Yes, what prevents userspace daemon watching /dev/input/event* to provide this functionality?

Well that was my first attempt. Just an hack, but it works. Nonetheless I found the kernel-level approach fitting better the problem: it is elegant, simpler and more efficient than user-level one.

For example, the subsystem provides at kernel-level handy hiberante/suspend/resume callbacks that I use to turn on/off the timer, avoiding the time-warp problem. Doing that at user-level would be far more messy...

Bye

--
An age is called Dark not because the light fails to shine, but because people refuse to see it. - James Michener, Space

#16 lore raw

Hi!

Quoted 10 lines
Quoted 3 lines

But I still believe it can be out.

Do you believe it could be a user-space daemon or what?

Yes, what prevents userspace daemon watching /dev/input/event* to provide this functionality?

Well that was my first attempt. Just an hack, but it works. Nonetheless I found the kernel-level approach fitting better the problem: it is elegant, simpler and more efficient than user-level one.

Well, unfortunately it is also wrong thing to do :-(.

Quoted 4 lines

For example, the subsystem provides at kernel-level handy hiberante/suspend/resume callbacks that I use to turn on/off the timer, avoiding the time-warp problem. Doing that at user-level would be far more messy...

Imagine for a moment that we solve time-warp somehow. Any other problems? [I'd really like to get "is user idle" solved, but it really should not be in kernel unless it _has_ to. And time-warp probably causes problems not only for your daemon.]
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#36 lore raw
In reply to Pavel Machek

On Tue, Jan 23, 2007 at 05:34:42PM +0100, Pavel Machek wrote:
[...]

Quoted 4 lines
Quoted 1 line

Do you believe it could be a user-space daemon or what?

Yes, what prevents userspace daemon watching /dev/input/event* to provide this functionality?

hmmm... EVIOCGRAB for example? the synaptics Xorg driver is using it, maybe others too?
I don't want to start a new discussion about it, just provide an answer to your question :)

Signature · 2 lines
mattia
:wq!
#37 lore raw
Quoted 11 lines · Mattia Dongili

On Tue, Jan 23, 2007 at 05:34:42PM +0100, Pavel Machek wrote:
[...]

Quoted 4 lines
Quoted 1 line

Do you believe it could be a user-space daemon or what?

Yes, what prevents userspace daemon watching /dev/input/event* to provide this functionality?

hmmm... EVIOCGRAB for example? the synaptics Xorg driver is using it, maybe others too?
I don't want to start a new discussion about it, just provide an answer to your question :)

I do not know how EVIOCGRAB works, I believe event* will _still_ see the events. Anyway, if not, I guess EVIOCGRAB can be fixed/removed/ we can add EVIOCGIVEMEALLTHEDATAREALLYIWANTIT.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#39 lore raw
In reply to Pavel Machek
Quoted 11 lines · Pavel Machek

Hi1
...

Quoted 5 lines

But I still believe it can be out.

Do you believe it could be a user-space daemon or what?

Yes, what prevents userspace daemon watching /dev/input/event* to provide this functionality?
Pavel

---

One possible argument is to allow integrating "input-like" user events with other kinds of system-level events that you might want to have treated like user activity. For instance, our definition of user activity includes: button presses, opening-closing the cover (on a phone), and plugging in or removing memory cards, accessories, or cables. We actually use a mix of kernel and user-space monitoring, today, but would prefer an integrated monitor.

A user-space monitor also has more opportunity for races - for instance, deciding that the inactivity timeout has occurred between the time that the user does something and the time that the kernel gets a notification up to user space.

My own hot button is making sure that the definition of what constitutes user activity is managed in exactly one place, whether in the kernel or not. My naive model would be to put the response at user level, but to provide a single point of definition in the kernel (say, /dev/useractivity or the equivalent) that the user-level daemon could listen to.

scott

#38 lore raw
In reply to Pavel Machek
Quoted 8 lines · Pavel Machek
Quoted 7 lines · Mattia Dongili

On Tue, Jan 23, 2007 at 05:34:42PM +0100, Pavel Machek wrote:
[...]

Quoted 4 lines
Quoted 1 line

Do you believe it could be a user-space daemon or what?

Yes, what prevents userspace daemon watching /dev/input/event* to provide this functionality?

Quoted 6 lines
Quoted 4 lines

hmmm... EVIOCGRAB for example? the synaptics Xorg driver is using it, maybe others too?
I don't want to start a new discussion about it, just provide an answer to your question :)

I do not know how EVIOCGRAB works, I believe event* will _still_ see

AFAIK once an opener has eviocgrab-ed the device no other opener will receive events.

Quoted 2 lines

the events. Anyway, if not, I guess EVIOCGRAB can be fixed/removed/ we can add EVIOCGIVEMEALLTHEDATAREALLYIWANTIT.

then probably pbuttonsd is already doing something similar to SI[NM] hmmm... was it pbuttonsd? oh, yes:
http://pbbuttons.sourceforge.net/projects/pbbuttonsd/

Signature · 2 lines
mattia
:wq!
#40 lore raw
In reply to Scott Preece

"Scott Preece" <[email protected]> writes:

My own hot button is making sure that the definition of what constitutes user activity is managed in exactly one place, whether in the kernel or not. My naive model would be to put the response at user level, but to provide a single point of definition in the kernel (say, /dev/useractivity or the equivalent) that the user-level daemon could listen to.

Unfortunately the term "user activity" seems a bit too vague for this. IMHO different users (but also applications) present different needs that you cannot fit with a single device node.

Example. The user expects that the keyboard light is turned off after 10 minutes of keyboard inactivity, disregarding the mouse movements. This makes sense since the glare at the bottom disturb the Quake sessions. :-) However when the screen is blanked, the user expects that either keyboard or mouse events can unblank it...

Signature · 1 line
All of the significant battles are waged within the self. - Sheldon Kopp
#17 lore raw
In reply to Pavel Machek

Pavel Machek <[email protected]> writes:

Imagine for a moment that we solve time-warp somehow. Any other problems?

Well, a user-level daemon have to process a lot of data just to detect user interaction. Considering that the trackpad bandwidth is nearly 5KB/sec, probably would be better to leave my panel alone... :-/

I'd really like to get "is user idle" solved, but it really should not be in kernel unless it _has_ to. And time-warp probably causes problems not only for your daemon.

IMHO signal the user-space is a kernel duty and no user-space daemon will ever make it better. There are plenty of PM daemons out there, but Linux still lacks of a decent power management. Thanks to SIN, acpid and a silly bash script I'm able to save a lot of battery and furthermore, when my friends see the dimming panel they break out: WOW, how do you succeed in running MacOS on your Vaio!?! :-(

Best,

Signature · 2 lines
Gratitude is not only the greatest of virtues, but the parent of all the
others. - Cicero
#35 lore raw
In reply to Pavel Machek
Quoted 4 lines · Pavel Machek

For example, the subsystem provides at kernel-level handy hiberante/suspend/resume callbacks that I use to turn on/off the timer, avoiding the time-warp problem. Doing that at user-level would be far more messy...

Imagine for a moment that we solve time-warp somehow. Any other problems? [I'd really like to get "is user idle" solved, but it really should not be in kernel unless it _has_ to. And time-warp probably causes problems not only for your daemon.]

Hi,
the two patches in attachment fix the time-warp problem and remove the procfs support. Feel free to contact me when you'll find a better way, maybe I could help.

Best,

Quoted 1 line

From 602a3340fa5b11e6cfff91719f85668980bb338b Mon Sep 17 00:00:00 2001

From: Alessandro Di Marco <[email protected]>
Date: Wed, 24 Jan 2007 18:28:47 +0100
Subject: [PATCH] Time-warp bug fixed

---
 Makefile |    2 +
 debug.h  |   36 +++++++++++++
 sin.c    |  174 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 sin.h    |   13 +++++
 table.c  |   45 +++++++++-------
 table.h  |    6 +--
 6 files changed, 239 insertions(+), 37 deletions(-)
Makefile +2 -0
index d45fa58..8b80de6 100644
@@ -1,5 +1,7 @@
 MODLPATH = kernel/drivers/char
 
+#DEBUG="-D SIN_DEBUG"
+
 MODL = sinmod
 OBJS = sin.o procfs.o sysfs.o table.o input_enumerator.o acpi_enumerator.o
 
debug.h new file +36 -0
new file mode 100644
index 0000000..e1c4bcc
@@ -0,0 +1,36 @@
+/*
+ *  Copyright (C) 2007 Alessandro Di Marco
+ */
+
+/*
+ *  This file is part of SIN.
+ *
+ *  SIN is free software; you can redistribute it and/or modify it under the
+ *  terms of the GNU General Public License as published by the Free Software
+ *  Foundation; version 2 of the License.
+ *
+ *  SIN is distributed in the hope that it will be useful, but WITHOUT ANY
+ *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ *  details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with SIN; if not, write to the Free Software Foundation, Inc., 51 Franklin
+ *  St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef DEBUG_H
+#define DEBUG_H
+
+#ifdef SIN_DEBUG
+extern int debug;
+#define set_debug(val) debug = (val)
+#define printd(fmt...) if (unlikely(debug)) { printk("SIN: " fmt); }
+#else
+#define SORRY "SIN: debugging support was disabled at compile time, sorry!\n"
+
+#define set_debug(val) if (val) { printk(KERN_DEBUG SORRY); }
+#define printd(fmt...)
+#endif
+
+#endif /* DEBUG_H */
sin.c +162 -12

269 lines not on this page · raw message

sin.h +13 -0
index 1ef52d2..929b1e5 100644
@@ -59,6 +59,19 @@ static inline unsigned long last_activity(struct user_activity *uact)
 	return last;
 }
 
+static inline unsigned long trim_activity(struct user_activity *uact,
+					  unsigned long offset)
+{
+	unsigned long last;
+
+	spin_lock(&uact->lock);
+	last = jiffies;
+	uact->last = (long) last - (long) offset;
+	spin_unlock(&uact->lock);
+
+	return last;
+}
+
 extern unsigned long simulate_activity(void);
 extern void signal_interaction(void);
 extern void simulate_event(void);
table.c +25 -20

85 lines not on this page · raw message

table.h +1 -5
index fd6b91f..d2a86ae 100644
@@ -39,11 +39,6 @@ struct table {
 	struct rule *rules;
 };
 
-#define printd(fmt...)				\
-	if (unlikely(rt.debug)) {		\
-		printk(fmt);			\
-	}
-
 static inline int tablecmp(struct table *l, struct table *r)
 {
 	if (l->debug != r->debug ||
@@ -73,6 +68,7 @@ static inline int tablecmp(struct table *l, struct table *r)
 
 #define TABLE_BUFFER_SIZE (8 + rt.dnum + rt.rnum * 3 + (TABLE_SIZE << 3) / 3)
 
+extern void special_event(struct acpi_device *acpi_device);
 extern unsigned long occasionally_generate_event(struct acpi_device *acpi_device, unsigned long last);
 extern unsigned long timely_generate_event(struct acpi_device *acpi_device, unsigned long last, unsigned long *notify);
 
Signature · 1 line
1.4.4.4
Quoted 1 line

From 3769b408303337db46b7e7621d5749b98ad9b198 Mon Sep 17 00:00:00 2001

From: Alessandro Di Marco <[email protected]>
Date: Wed, 24 Jan 2007 18:45:40 +0100
Subject: [PATCH] Removed procfs support

---
 Makefile |    2 +-
 gentable |   21 ++++---
 procfs.c |  202 --------------------------------------------------------------
 procfs.h |   33 ----------
 sin.c    |   10 ---
 5 files changed, 14 insertions(+), 254 deletions(-)
Makefile +1 -1
index 8b80de6..62b1c43 100644
@@ -3,7 +3,7 @@ MODLPATH = kernel/drivers/char
 #DEBUG="-D SIN_DEBUG"
 
 MODL = sinmod
-OBJS = sin.o procfs.o sysfs.o table.o input_enumerator.o acpi_enumerator.o
+OBJS = sin.o sysfs.o table.o input_enumerator.o acpi_enumerator.o
 
 SRCS := $(patsubst %.o,%.c,$(OBJS))
 HDRS := $(patsubst %.o,%.h,$(OBJS))
gentable +13 -8
index 49af1f4..a8fe292 100755
@@ -24,8 +24,8 @@ if (( $# == 0 )); then
    exit
 fi
 
-if [ ! -d "/proc/sin" ]; then
-    echo "/proc/sin not found, has sinmod been loaded?"
+if [ ! -d "/sys/class/misc/sin" ]; then
+    echo "/sys/class/misc/sin not found, has sinmod been loaded?"
     exit
 fi
 
@@ -38,7 +38,7 @@ least one device and must not specify duplicates.
 EOF
 
 echo -e "Specify the the input devices you want to monitor from the list below:\n"
-cat /proc/sin/input
+cat /sys/class/misc/sin/input
 
 echo
 input "Please digit the corresponding numbers separated by spaces" devs
@@ -57,7 +57,7 @@ suitable handler that will be used as originator.
 EOF
 
 echo -e "Specify the acpi handler you want to use from the list below:\n"
-cat /proc/sin/acpi
+cat /sys/class/misc/sin/acpi
 
 echo
 input "Please enter the number corresponding to the handler" handle
@@ -83,6 +83,8 @@ finished, just press enter.
 
 EOF
 
+declare -i i
+
 for (( i = 0; ; i++ )); do
     input "Rule ${i}?" rule
 
@@ -95,6 +97,7 @@ done
 
 if (( ${i} == 0 )); then
     rules[0]="60 1 2"
+    i=${i}+1
 fi
 
 cat <<EOF
@@ -111,6 +114,8 @@ if [ -z "${resume}" ]; then
     resume="2 1"
 fi
 
+declare -i j=${i}-1
+
 cat <<EOF
 
 Often an SIN event results in suspending or hibernating the system, hibernate,
@@ -120,10 +125,10 @@ consequence, no event will ever be generated and the system will remain in the
 state associated with the next-to-last rule (e.g. blanked screen, wireless
 powered off, etc.). The next option allows you to request a special event,
 restarting the rule-list evaluation from an arbitrary position.  Possible value
-ranges are described below, where N is the rule-list size:
+ranges are described below:
 
-    [0, N - 1]	=> jump to the given rule
-    N		=> go to sleep and wait for user interaction
+    [0, ${j}]	=> jump to the given rule
+    ${i}		=> go to sleep and wait for user interaction
 
 EOF
 
@@ -144,7 +149,7 @@ cat <<EOF
 All done. Now you can try your newly generated table as follows:
 
 # modprobe sinmod
-# echo $1 >/proc/sin/table
+# echo $1 >/sys/class/misc/sin/table
 
 An "Invalid argument" error indicates a mismatch in the table file, usually due
 to specifying an invalid acpi or input device. In that case, restart from
procfs.c deleted +0 -202

202 lines not on this page · raw message

procfs.h deleted +0 -33
deleted file mode 100644
index ea164be..0000000
@@ -1,33 +0,0 @@
-/*
- *  Copyright (C) 2007 Alessandro Di Marco
- */
-
-/*
- *  This file is part of SIN.
- *
- *  SIN is free software; you can redistribute it and/or modify it under the
- *  terms of the GNU General Public License as published by the Free Software
- *  Foundation; version 2 of the License.
- *
- *  SIN is distributed in the hope that it will be useful, but WITHOUT ANY
- *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- *  details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with SIN; if not, write to the Free Software Foundation, Inc., 51 Franklin
- *  St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef PROCFS_H
-#define PROCFS_H
-
-struct procfs_bs {
-	char *page;
-	int size;
-};
-
-extern int start_procfs(void);
-extern void stop_procfs(void);
-
-#endif /* PROCFS_H */
sin.c +0 -10
index bf06999..7b96c61 100644
@@ -30,7 +30,6 @@
 
 #include "sin.h"
 #include "table.h"
-#include "procfs.h"
 #include "sysfs.h"
 #include "acpi_enumerator.h"
 #include "input_enumerator.h"
@@ -275,18 +274,10 @@ static int __devinit sin_probe(struct platform_device *dev)
 		goto cleanout3;
 	}
 
-	err = start_procfs();
-	if (err < 0) {
-		printk(KERN_ERR "SIN: procfs initialization failed\n");
-		goto cleanout4;
-	}
-
 	printk(KERN_DEBUG "System Inactivity Notifier 1.5 - (c) Alessandro Di Marco <[email protected]>\n");
 
 	return 0;
 
-cleanout4:
-	stop_sysfs();
 cleanout3:
 	free_acpi_enum();
 cleanout2:
@@ -299,7 +290,6 @@ out:
 
 static int __devexit sin_remove(struct platform_device *dev)
 {
-	stop_procfs();
 	stop_sysfs();
 	free_acpi_enum();
 	free_input_enum();
Signature · 1 line
1.4.4.4
Signature · 3 lines
-- 
Advertising is a valuable economic factor because it is the cheapest way of
selling goods, particularly if the goods are worthless. - Sinclair Lewis
#41 lore raw
In reply to Scott Preece

Hi!

Quoted 12 lines
Quoted 10 lines
Quoted 4 lines

But I still believe it can be out.

Do you believe it could be a user-space daemon or

what?

Yes, what prevents userspace daemon watching
/dev/input/event* to
provide this functionality?
Pavel

---

Quoted 12 lines

One possible argument is to allow integrating "input-like" user events
with other kinds of system-level events that you might want to have
treated like user activity. For instance, our definition of user
activity includes: button presses, opening-closing the cover (on a
phone), and plugging in or removing memory cards, accessories, or
cables. We actually use a mix of kernel and user-space monitoring,

Well... input already has 'pseudokey' for lid, and yes, you probably can monitor cover, memory cards and cables from userspace, already... as you do. Cover, and maybe even cards/cables could be integrated with input infrastructure, too.

(Still waiting for you to start selling those cool phones in czech republic :-).

Quoted 7 lines

A user-space monitor also has more opportunity for races
- for
instance, deciding that the inactivity timeout has occurred between
the time that the user does something and the time that the kernel
gets a notification up to user space.

Same races are inside kernel, too.

Quoted 11 lines

My own hot button is making sure that the definition of what
constitutes user activity is managed in exactly one place, whether in
the kernel or not. My naive model would be to put the response at user
level, but to provide a single point of definition in the kernel (say,
/dev/useractivity or the equivalent) that the user-level daemon could
listen to.

Actually, I believe right solution is to provide one, unified, monitoring daemon, using whatever interfaces are available. (+ add missing functionality to the kernel, if neccessary).

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#18 lore raw
In reply to Alessandro Di Marco

Hi!

Quoted 6 lines

Imagine for a moment that we solve time-warp somehow. Any other problems?

Well, a user-level daemon have to process a lot of data just to detect user interaction. Considering that the trackpad bandwidth is nearly 5KB/sec, probably would be better to leave my panel alone... :-/

Ok, so we may want to introduce something like "tell me if some data came from last time"... Actually, 5KB/sec is pretty much okay, and you probably could get around actually reading that data.

When you know user is moving the touchpad, you could just sleep for 5 seconds (assuming user activity) and only then start monitoring it again?

Quoted 6 lines

I'd really like to get "is user idle" solved, but it really should not be in kernel unless it _has_ to. And time-warp probably causes problems not only for your daemon.

IMHO signal the user-space is a kernel duty and no user-space daemon will ever make it better. There are plenty of PM daemons out there, but Linux still lacks

Well, I do not think your kernel code is mergeable. But bits to enable similar functionality in userspace probably would be mergeable.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#19 lore raw

Pavel Machek <[email protected]> writes:

Well, I do not think your kernel code is mergeable. But bits to enable similar functionality in userspace probably would be mergeable.

You said it :-)

This patch exports to the user space the inactivity time (in msecs) of a given input device. Example follows:

<0> $ cat /proc/bus/input/activity

0011 0001 0001 ab41     1
0011 0002 0008 0000     3160799
0011 0002 0008 7321     549991
0019 0000 0005 0000     3160799
0019 0000 0001 0000     3454901
0010 104d 0000 0000     3160799
0010 104d 0000 0000     2162833

The device ordering matches the /proc/bus/input/devices one, anyway I reported also vendor, product, etc. Now the daemon is trivial...

Bye

Ah, the interesting column is the fifth ;-)

drivers/input/input.c +44 -1
diff -ur OLD/drivers/input/input.c NEW/drivers/input/input.c
@@ -49,6 +49,8 @@
 {
 	struct input_handle *handle;
 
+	dev->last_activity = jiffies;
+
 	if (type > EV_MAX || !test_bit(type, dev->evbit))
 		return;
 
@@ -482,6 +484,30 @@
 	return seq_open(file, &input_devices_seq_ops);
 }
 
+static int input_activity_seq_show(struct seq_file *seq, void *v)
+{
+	struct input_dev *dev = container_of(v, struct input_dev, node);
+
+	seq_printf(seq, "%04x %04x %04x %04x\t%u\n",
+		   dev->id.bustype, dev->id.vendor,
+		   dev->id.product, dev->id.version,
+		   jiffies_to_msecs((long) jiffies - (long) dev->last_activity));
+
+	return 0;
+}
+
+static struct seq_operations input_activity_seq_ops = {
+	.start	= input_devices_seq_start,
+	.next	= input_devices_seq_next,
+	.stop	= input_devices_seq_stop,
+	.show	= input_activity_seq_show,
+};
+
+static int input_proc_activity_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &input_activity_seq_ops);
+}
+
 static struct file_operations input_devices_fileops = {
 	.owner		= THIS_MODULE,
 	.open		= input_proc_devices_open,
@@ -491,6 +517,15 @@
 	.release	= seq_release,
 };
 
+static struct file_operations input_activity_fileops = {
+	.owner		= THIS_MODULE,
+	.open		= input_proc_activity_open,
+	.poll		= input_proc_devices_poll,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= seq_release,
+};
+
 static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos)
 {
 	/* acquire lock here ... Yes, we do need locking, I knowi, I know... */
@@ -558,15 +593,23 @@
 	entry->owner = THIS_MODULE;
 	entry->proc_fops = &input_devices_fileops;
 
-	entry = create_proc_entry("handlers", 0, proc_bus_input_dir);
+	entry = create_proc_entry("activity", 0, proc_bus_input_dir);
 	if (!entry)
 		goto fail2;
 
 	entry->owner = THIS_MODULE;
+	entry->proc_fops = &input_activity_fileops;
+
+	entry = create_proc_entry("handlers", 0, proc_bus_input_dir);
+	if (!entry)
+		goto fail3;
+
+	entry->owner = THIS_MODULE;
 	entry->proc_fops = &input_handlers_fileops;
 
 	return 0;
 
+ fail3:	remove_proc_entry("activity", proc_bus_input_dir);
  fail2:	remove_proc_entry("devices", proc_bus_input_dir);
  fail1: remove_proc_entry("input", proc_bus);
 	return -ENOMEM;
include/linux/input.h +2 -0
diff -ur OLD/include/linux/input.h NEW/include/linux/input.h
@@ -949,6 +949,8 @@
 	const char *uniq;
 	struct input_id id;
 
+	unsigned long last_activity;
+	
 	unsigned long evbit[NBITS(EV_MAX)];
 	unsigned long keybit[NBITS(KEY_MAX)];
 	unsigned long relbit[NBITS(REL_MAX)];
Signature · 3 lines
-- 
I don't think anyone should write their autobiography until after they're
dead. - Samuel Goldwyn
#20 lore raw

Hi!

Quoted 7 lines

Well, I do not think your kernel code is mergeable. But bits to enable similar functionality in userspace probably would be mergeable.

You said it :-)

This patch exports to the user space the inactivity time (in msecs) of a given input device. Example follows:

Looks okay to me. I guess you should sign it off, and ask Dmitry (input maintainer) for a merge?

Quoted 101 lines

<0> $ cat /proc/bus/input/activity

0011 0001 0001 ab41     1
0011 0002 0008 0000     3160799
0011 0002 0008 7321     549991
0019 0000 0005 0000     3160799
0019 0000 0001 0000     3454901
0010 104d 0000 0000     3160799
0010 104d 0000 0000     2162833

The device ordering matches the /proc/bus/input/devices one, anyway I reported also vendor, product, etc. Now the daemon is trivial...

drivers/input/input.c +42 -1
@@ -482,6 +484,30 @@
 	return seq_open(file, &input_devices_seq_ops);
 }
 
+static int input_activity_seq_show(struct seq_file *seq, void *v)
+{
+	struct input_dev *dev = container_of(v, struct input_dev, node);
+
+	seq_printf(seq, "%04x %04x %04x %04x\t%u\n",
+		   dev->id.bustype, dev->id.vendor,
+		   dev->id.product, dev->id.version,
+		   jiffies_to_msecs((long) jiffies - (long) dev->last_activity));
+
+	return 0;
+}
+
+static struct seq_operations input_activity_seq_ops = {
+	.start	= input_devices_seq_start,
+	.next	= input_devices_seq_next,
+	.stop	= input_devices_seq_stop,
+	.show	= input_activity_seq_show,
+};
+
+static int input_proc_activity_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &input_activity_seq_ops);
+}
+
 static struct file_operations input_devices_fileops = {
 	.owner		= THIS_MODULE,
 	.open		= input_proc_devices_open,
@@ -491,6 +517,15 @@
 	.release	= seq_release,
 };
 
+static struct file_operations input_activity_fileops = {
+	.owner		= THIS_MODULE,
+	.open		= input_proc_activity_open,
+	.poll		= input_proc_devices_poll,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= seq_release,
+};
+
 static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos)
 {
 	/* acquire lock here ... Yes, we do need locking, I knowi, I know... */
@@ -558,15 +593,23 @@
 	entry->owner = THIS_MODULE;
 	entry->proc_fops = &input_devices_fileops;
 
-	entry = create_proc_entry("handlers", 0, proc_bus_input_dir);
+	entry = create_proc_entry("activity", 0, proc_bus_input_dir);
 	if (!entry)
 		goto fail2;
 
 	entry->owner = THIS_MODULE;
+	entry->proc_fops = &input_activity_fileops;
+
+	entry = create_proc_entry("handlers", 0, proc_bus_input_dir);
+	if (!entry)
+		goto fail3;
+
+	entry->owner = THIS_MODULE;
 	entry->proc_fops = &input_handlers_fileops;
 
 	return 0;
 
+ fail3:	remove_proc_entry("activity", proc_bus_input_dir);
  fail2:	remove_proc_entry("devices", proc_bus_input_dir);
  fail1: remove_proc_entry("input", proc_bus);
 	return -ENOMEM;

diff -ur OLD/include/linux/input.h NEW/include/linux/input.h

include/linux/input.h +2 -0
@@ -949,6 +949,8 @@
 	const char *uniq;
 	struct input_id id;
 
+	unsigned long last_activity;
+	
 	unsigned long evbit[NBITS(EV_MAX)];
 	unsigned long keybit[NBITS(KEY_MAX)];
 	unsigned long relbit[NBITS(REL_MAX)];
Signature · 3 lines
-- 
I don't think anyone should write their autobiography until after they're
dead. - Samuel Goldwyn
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#21 lore raw
Quoted 5 lines · Pavel Machek

Hi!

Quoted 3 lines

Well, I do not think your kernel code is mergeable. But bits to enable similar functionality in userspace probably would be mergeable.

Quoted 7 lines
Quoted 4 lines

You said it :-)

This patch exports to the user space the inactivity time (in msecs) of a given input device. Example follows:

Looks okay to me. I guess you should sign it off, and ask Dmitry (input maintainer) for a merge?

The /proc/bus/input/devices has an extensible structure. You can just add an "A:" line (for Activity) instead of adding a new proc file. Anyway, I believe this should be also available through sysfs, if not only there.

Also, the activity counters should IMO coincide with the event times passed through /dev/input/event, and should not be jiffies based. Ideally, both should be based on clock_gettime(CLOCK_MONOTONIC).

Quoted 107 lines
Quoted 101 lines

<0> $ cat /proc/bus/input/activity

0011 0001 0001 ab41     1
0011 0002 0008 0000     3160799
0011 0002 0008 7321     549991
0019 0000 0005 0000     3160799
0019 0000 0001 0000     3454901
0010 104d 0000 0000     3160799
0010 104d 0000 0000     2162833

The device ordering matches the /proc/bus/input/devices one, anyway I reported also vendor, product, etc. Now the daemon is trivial...

drivers/input/input.c +42 -1
@@ -482,6 +484,30 @@
 	return seq_open(file, &input_devices_seq_ops);
 }
 
+static int input_activity_seq_show(struct seq_file *seq, void *v)
+{
+	struct input_dev *dev = container_of(v, struct input_dev, node);
+
+	seq_printf(seq, "%04x %04x %04x %04x\t%u\n",
+		   dev->id.bustype, dev->id.vendor,
+		   dev->id.product, dev->id.version,
+		   jiffies_to_msecs((long) jiffies - (long) dev->last_activity));
+
+	return 0;
+}
+
+static struct seq_operations input_activity_seq_ops = {
+	.start	= input_devices_seq_start,
+	.next	= input_devices_seq_next,
+	.stop	= input_devices_seq_stop,
+	.show	= input_activity_seq_show,
+};
+
+static int input_proc_activity_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &input_activity_seq_ops);
+}
+
 static struct file_operations input_devices_fileops = {
 	.owner		= THIS_MODULE,
 	.open		= input_proc_devices_open,
@@ -491,6 +517,15 @@
 	.release	= seq_release,
 };
 
+static struct file_operations input_activity_fileops = {
+	.owner		= THIS_MODULE,
+	.open		= input_proc_activity_open,
+	.poll		= input_proc_devices_poll,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= seq_release,
+};
+
 static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos)
 {
 	/* acquire lock here ... Yes, we do need locking, I knowi, I know... */
@@ -558,15 +593,23 @@
 	entry->owner = THIS_MODULE;
 	entry->proc_fops = &input_devices_fileops;
 
-	entry = create_proc_entry("handlers", 0, proc_bus_input_dir);
+	entry = create_proc_entry("activity", 0, proc_bus_input_dir);
 	if (!entry)
 		goto fail2;
 
 	entry->owner = THIS_MODULE;
+	entry->proc_fops = &input_activity_fileops;
+
+	entry = create_proc_entry("handlers", 0, proc_bus_input_dir);
+	if (!entry)
+		goto fail3;
+
+	entry->owner = THIS_MODULE;
 	entry->proc_fops = &input_handlers_fileops;
 
 	return 0;
 
+ fail3:	remove_proc_entry("activity", proc_bus_input_dir);
  fail2:	remove_proc_entry("devices", proc_bus_input_dir);
  fail1: remove_proc_entry("input", proc_bus);
 	return -ENOMEM;

diff -ur OLD/include/linux/input.h NEW/include/linux/input.h

include/linux/input.h +2 -0
@@ -949,6 +949,8 @@
 	const char *uniq;
 	struct input_id id;
 
+	unsigned long last_activity;
+	
 	unsigned long evbit[NBITS(EV_MAX)];
 	unsigned long keybit[NBITS(KEY_MAX)];
 	unsigned long relbit[NBITS(REL_MAX)];
Signature · 3 lines
-- 
I don't think anyone should write their autobiography until after they're
dead. - Samuel Goldwyn
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Signature · 2 lines
Vojtech Pavlik
Director SuSE Labs
#34 lore raw
In reply to Pavel Machek
Quoted 5 lines · Pavel Machek
Quoted 2 lines

This patch exports to the user space the inactivity time (in msecs) of a given input device. Example follows:

Looks okay to me. I guess you should sign it off, and ask Dmitry (input maintainer) for a merge?

Hey, come on, "no new proc files", please ;-)

Quoted 1 line
Quoted 1 line

<0> $ cat /proc/bus/input/activity

Signature · 3 lines
Stefan Seyfried
QA / R&D Team Mobile Devices        |              "Any ideas, John?"
SUSE LINUX Products GmbH, Nürnberg  | "Well, surrounding them's out." 
#22 lore raw
In reply to Vojtech Pavlik

Vojtech Pavlik <[email protected]> writes:

Quoted 5 lines · Pavel Machek

Hi!

Quoted 3 lines

Well, I do not think your kernel code is mergeable. But bits to enable similar functionality in userspace probably would be mergeable.

Quoted 7 lines
Quoted 4 lines

You said it :-)

This patch exports to the user space the inactivity time (in msecs) of a given input device. Example follows:

Looks okay to me. I guess you should sign it off, and ask Dmitry (input maintainer) for a merge?

Pavel, the submitted patch was not meant for production use: it still suffers of the time-warp problem. To fix it I need to know when the system goes to sleep/resumes. In SIN I've solved via the platform driver, introducing suspend() resume() callbacks. What do you think about?

The /proc/bus/input/devices has an extensible structure. You can just add an "A:" line (for Activity) instead of adding a new proc file.

I know, but IMO there is too much stuff to parse in there. Activity counters are frequently accessed by daemons, and four or five concurrent daemons are the norm in a typical X11 linux box...

Anyway, I believe this should be also available through sysfs, if not only there.

Pavel gives me clearance for only bits of code, so I've recycled something already done. No problem for me to switch /sys.

Also, the activity counters should IMO coincide with the event times passed through /dev/input/event, and should not be jiffies based. Ideally, both should be based on clock_gettime(CLOCK_MONOTONIC).

In evdev.c do_gettimeofday() is used. Anyway I just need of a monotonic counter, so get_jiffies_64() wouldn't be better? It isn't affected by wrapping issues and it is probably faster than do_gtod().

Best,

--
Ambition is a poor excuse for not having sense enough to be lazy. - Edgar Bergen

#23 lore raw

Hi!

Quoted 6 lines

The /proc/bus/input/devices has an extensible structure. You can just add an "A:" line (for Activity) instead of adding a new proc file.

I know, but IMO there is too much stuff to parse in there. Activity counters are frequently accessed by daemons, and four or five concurrent daemons are the norm in a typical X11 linux box...

Syscalls are fast enough, and the file is _very_ easy (=> fast) to parse.

Quoted 7 lines

Also, the activity counters should IMO coincide with the event times passed through /dev/input/event, and should not be jiffies based. Ideally, both should be based on clock_gettime(CLOCK_MONOTONIC).

In evdev.c do_gettimeofday() is used. Anyway I just need of a monotonic counter, so get_jiffies_64() wouldn't be better? It isn't affected by wrapping issues and it is probably faster than do_gtod().

Just use same time source rest of inputs already do...
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#24 lore raw

Pavel Machek <[email protected]> writes:

Hi!

Quoted 6 lines

The /proc/bus/input/devices has an extensible structure. You can just add an "A:" line (for Activity) instead of adding a new proc file.

I know, but IMO there is too much stuff to parse in there. Activity counters are frequently accessed by daemons, and four or five concurrent daemons are the norm in a typical X11 linux box...

Syscalls are fast enough, and the file is _very_ easy (=> fast) to parse.

Quoted 7 lines

Also, the activity counters should IMO coincide with the event times passed through /dev/input/event, and should not be jiffies based. Ideally, both should be based on clock_gettime(CLOCK_MONOTONIC).

In evdev.c do_gettimeofday() is used. Anyway I just need of a monotonic counter, so get_jiffies_64() wouldn't be better? It isn't affected by wrapping issues and it is probably faster than do_gtod().

Just use same time source rest of inputs already do...

OK, but what about the time-warp problem?. To fix it I need to know when the system goes to sleep/resumes. In SIN I've solved via the platform driver, introducing suspend() resume() callbacks...

greets,

Signature · 2 lines
Technology is dominated by two types of people: those who understand what they
do not manage, and those who manage what they do not understand. - Putt's Law
#25 lore raw

Hi!

Quoted 17 lines
Quoted 6 lines

The /proc/bus/input/devices has an extensible structure. You can just add an "A:" line (for Activity) instead of adding a new proc file.

I know, but IMO there is too much stuff to parse in there. Activity counters are frequently accessed by daemons, and four or five concurrent daemons are the norm in a typical X11 linux box...

Syscalls are fast enough, and the file is _very_ easy (=> fast) to parse.

Quoted 7 lines

Also, the activity counters should IMO coincide with the event times passed through /dev/input/event, and should not be jiffies based. Ideally, both should be based on clock_gettime(CLOCK_MONOTONIC).

In evdev.c do_gettimeofday() is used. Anyway I just need of a monotonic counter, so get_jiffies_64() wouldn't be better? It isn't affected by wrapping issues and it is probably faster than do_gtod().

Quoted 5 lines

Just use same time source rest of inputs already do...

OK, but what about the time-warp problem?. To fix it I need to know when the system goes to sleep/resumes. In SIN I've solved via the platform driver, introducing suspend() resume() callbacks...

input drivers will already have suspend() resume() callbacks... could you reuse those?

...hmm, I see no easy place where to hook these. You could reuse your platform device trick, I guess... but maybe there's a better way?

Vojtech, do we have some "global" hooks for input suspend/resume? This code is global to all the devices, but still needs to know about suspend/resume...

Or we could create notifier list, where interested parties would be informed of suspend/resume...
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#26 lore raw
In reply to Alessandro Di Marco
Quoted 21 lines · Alessandro Di Marco

Pavel Machek <[email protected]> writes:

Hi!

Quoted 6 lines

The /proc/bus/input/devices has an extensible structure. You can just add an "A:" line (for Activity) instead of adding a new proc file.

I know, but IMO there is too much stuff to parse in there. Activity counters are frequently accessed by daemons, and four or five concurrent daemons are the norm in a typical X11 linux box...

Syscalls are fast enough, and the file is _very_ easy (=> fast) to parse.

Quoted 7 lines

Also, the activity counters should IMO coincide with the event times passed through /dev/input/event, and should not be jiffies based. Ideally, both should be based on clock_gettime(CLOCK_MONOTONIC).

In evdev.c do_gettimeofday() is used. Anyway I just need of a monotonic counter, so get_jiffies_64() wouldn't be better? It isn't affected by wrapping issues and it is probably faster than do_gtod().

Quoted 5 lines

Just use same time source rest of inputs already do...

OK, but what about the time-warp problem?. To fix it I need to know when the system goes to sleep/resumes. In SIN I've solved via the platform driver, introducing suspend() resume() callbacks...

Well, you just need to make sure that a resume() actually is a visible event ...

Signature · 2 lines
Vojtech Pavlik
Director SuSE Labs
#27 lore raw

Vojtech Pavlik <[email protected]> writes:

Quoted 3 lines · Alessandro Di Marco

OK, but what about the time-warp problem?. To fix it I need to know when the system goes to sleep/resumes. In SIN I've solved via the platform driver, introducing suspend() resume() callbacks...

Well, you just need to make sure that a resume() actually is a visible event ...

Sorry, but I don't see the point. Visible to what?

Mine problem here is that the input device doesn't care about suspend/resume cycles (it is a straight char driver), probably because it doesn't need to (so far.) Low-level drivers (kbd & co) on the contrary are all bus or platform drivers, hooking directly into suspend/resume callbacks.

Do you mean that I should back-propagate a suspend/resume event from the low-level drivers to the input one?

Signature · 2 lines
There is only one thing a philosopher can be relied upon to do, and that is to
contradict other philosophers. - William James
#28 lore raw
Quoted 4 lines · Alessandro Di Marco

Vojtech Pavlik <[email protected]> writes:

On Mon, Jan 29, 2007 at 11:42:08PM +0100, Alessandro Di Marco wrote:

Quoted 8 lines
Quoted 3 lines

OK, but what about the time-warp problem?. To fix it I need to know when the system goes to sleep/resumes. In SIN I've solved via the platform driver, introducing suspend() resume() callbacks...

Well, you just need to make sure that a resume() actually is a visible event ...

Sorry, but I don't see the point. Visible to what?

Counted as activity.

Quoted 7 lines

Mine problem here is that the input device doesn't care about suspend/resume cycles (it is a straight char driver), probably because it doesn't need to (so far.) Low-level drivers (kbd & co) on the contrary are all bus or platform drivers, hooking directly into suspend/resume callbacks.

Do you mean that I should back-propagate a suspend/resume event from the low-level drivers to the input one?

Yes, but not as a callback, but instead as an input event.

Signature · 2 lines
Vojtech Pavlik
Director SuSE Labs
#29 lore raw
Quoted 7 lines · Vojtech Pavlik

Mine problem here is that the input device doesn't care about suspend/resume cycles (it is a straight char driver), probably because it doesn't need to (so far.) Low-level drivers (kbd & co) on the contrary are all bus or platform drivers, hooking directly into suspend/resume callbacks.

Do you mean that I should back-propagate a suspend/resume event from the low-level drivers to the input one?

Yes, but not as a callback, but instead as an input event.

Hum. Usually I'm not so dumb, really.

Problem) I need to know when the system goes to sleep in drivers/input/input.c. For example, as a consequence of 'echo mem

Quoted 1 line

/sys/power/state'.

Solution 1) My ideal input layer model would be:

               | SUBSYSTEM INPUT DEVICE* |
                   ^  ^      ^       ^
            +------+  |      +----+  +------+ events 
            |         |           |         |
        |KEYBOARD| |MOUSE | |TOUCHSCREEN| |MISC  |
        |DEVICE  | |DEVICE| |DEVICE     | |DEVICE|
               | SUBSYSTEM INPUT DEVICE* |
                   |  |      |       |
            +------+  |      +----+  +------+ suspend()/resume() callbacks
            v         v           v         v
        |KEYBOARD| |MOUSE | |TOUCHSCREEN| |MISC  |
        |DEVICE  | |DEVICE| |DEVICE     | |DEVICE|

Solution 2) On the contrary, you are suggesting to do this:

               |          INPUT DEVICE          |
                   ^     ^      ^           ^
            +------+     |      +----+      +------+ events plus
            |            |           |             | suspend/resume
        |KEYBOARD | |MOUSE    | |TOUCHSCREEN| |MISC      |
        |SUBSYSTEM| |SUBSYSTEM| |SUBSYSTEM  | |SUBSYSTEM |
        |DEVICE*  | |DEVICE*  | |DEVICE*    | |DEVICE*   |

Right?

* or whatever provides suspend/resume callbacks

Quoted 1 line

From their experience or from the recorded experience of others (history), men

learn only what their passions and their metaphysical prejudices allow them to learn. - Aldous Huxley

#30 lore raw

Re: [PATCH] input: Activity counters

In reply to Vojtech Pavlik

Hi. I think to have sorted out every issues at last; maybe you are still interested in merging activity counters.

Best,

Vojtech Pavlik <[email protected]> writes:

Quoted 21 lines · Alessandro Di Marco

Pavel Machek <[email protected]> writes:

Hi!

Quoted 6 lines

The /proc/bus/input/devices has an extensible structure. You can just add an "A:" line (for Activity) instead of adding a new proc file.

I know, but IMO there is too much stuff to parse in there. Activity counters are frequently accessed by daemons, and four or five concurrent daemons are the norm in a typical X11 linux box...

Syscalls are fast enough, and the file is _very_ easy (=> fast) to parse.

Quoted 7 lines

Also, the activity counters should IMO coincide with the event times passed through /dev/input/event, and should not be jiffies based. Ideally, both should be based on clock_gettime(CLOCK_MONOTONIC).

In evdev.c do_gettimeofday() is used. Anyway I just need of a monotonic counter, so get_jiffies_64() wouldn't be better? It isn't affected by wrapping issues and it is probably faster than do_gtod().

Quoted 5 lines

Just use same time source rest of inputs already do...

OK, but what about the time-warp problem?. To fix it I need to know when the system goes to sleep/resumes. In SIN I've solved via the platform driver, introducing suspend() resume() callbacks...

Well, you just need to make sure that a resume() actually is a visible event ...

Hello,

the attached patch* introduces activity counters into input device drivers so that a proper user-space daemon leveraging these counters can implement event notification facilities (e.g. screen savers, intrusion detection, etc.) At this purpose, a second patch has been also attached: it provides a working Perl daemon simulating a screen saver activity.

I had submitted something similar a couple of years ago, by way of a kernel module named SIN (http://lkml.org/lkml/2007/1/18/138)

Despite SIN has been properly maintained in this period, it revealed soon some design weaknesses which urged me towards alternative approaches. The resulting patch is quite straightforward yet provides good features, such as:

1) daemons retain the whole control logic

2) daemons are EVIOCGRAB hassle free

3) daemons do not get biased towards a specific environment (e.g. one monitor, one keyboard...)

That's it.

Cheers,
Alessandro

* 2.6.28.1 friendly

==============================================================================

drivers/input/input.c +49 -0
diff -uprN old/drivers/input/input.c new/drivers/input/input.c
@@ -72,6 +72,12 @@ static void input_pass_event(struct inpu
 			     unsigned int type, unsigned int code, int value)
 {
 	struct input_handle *handle;
+	
+	dev->activity = ktime_get();
+
+	if (dev->activity_notifier) {
+		sysfs_notify_dirent(dev->activity_notifier);
+	}
 
 	rcu_read_lock();
 
@@ -1012,11 +1018,25 @@ static ssize_t input_dev_show_modalias(s
 }
 static DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL);
 
+static ssize_t input_dev_show_activity(struct device *dev,
+				       struct device_attribute *attr,
+				       char *buf)
+{
+	struct input_dev *id = to_input_dev(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "A: %Ld\nD: %Ld\n",
+			 ktime_to_ns(id->activity),
+			 ktime_to_us(ktime_sub(ktime_get(), id->activity)));
+}
+
+static DEVICE_ATTR(activity, S_IRUGO, input_dev_show_activity, NULL);
+
 static struct attribute *input_dev_attrs[] = {
 	&dev_attr_name.attr,
 	&dev_attr_phys.attr,
 	&dev_attr_uniq.attr,
 	&dev_attr_modalias.attr,
+	&dev_attr_activity.attr,
 	NULL
 };
 
@@ -1227,10 +1247,34 @@ static int input_dev_uevent(struct devic
 	return 0;
 }
 
+static inline int warp_activity(struct device *dev) 
+{
+	struct input_dev *id = to_input_dev(dev);
+
+	id->activity = ktime_sub(ktime_get(), id->activity);
+	return 0;
+}
+
+int input_dev_suspend(struct device *dev, pm_message_t state)
+{
+	if (state.event & (PM_EVENT_FREEZE|PM_EVENT_SUSPEND)) {
+		(void) warp_activity(dev);
+	}
+
+	return 0;
+}
+
+int input_dev_resume(struct device *dev)
+{
+	return warp_activity(dev);
+}
+
 static struct device_type input_dev_type = {
 	.groups		= input_dev_attr_groups,
 	.release	= input_dev_release,
 	.uevent		= input_dev_uevent,
+	.suspend	= input_dev_suspend,
+	.resume		= input_dev_resume,
 };
 
 struct class input_class = {
@@ -1401,6 +1445,8 @@ int input_register_device(struct input_d
 		dev->name ? dev->name : "Unspecified device", path ? path : "N/A");
 	kfree(path);
 
+	dev->activity_notifier = sysfs_get_dirent(dev->dev.kobj.sd, "activity");
+	
 	error = mutex_lock_interruptible(&input_mutex);
 	if (error) {
 		device_del(&dev->dev);
@@ -1446,6 +1492,9 @@ void input_unregister_device(struct inpu
 
 	mutex_unlock(&input_mutex);
 
+	sysfs_put(dev->activity_notifier);
+	dev->activity_notifier = NULL;
+
 	device_unregister(&dev->dev);
 }
 EXPORT_SYMBOL(input_unregister_device);
include/linux/input.h +3 -0
diff -uprN old/include/linux/input.h new/include/linux/input.h
@@ -1094,6 +1094,9 @@ struct input_dev {
 
 	struct input_handle *grab;
 
+	struct sysfs_dirent *activity_notifier;
+	ktime_t activity;
+	
 	spinlock_t event_lock;
 	struct mutex mutex;
 

==============================================================================

SIN.pl +259 -0

259 lines not on this page · raw message

#31 lore raw

Re: [PATCH] input: Activity counters

In reply to Vojtech Pavlik

Hi. I think to have sorted out every issues at last; maybe you are still interested in merging activity counters.

Best,

Vojtech Pavlik <[email protected]> writes:

Quoted 21 lines · Alessandro Di Marco

Pavel Machek <[email protected]> writes:

Hi!

Quoted 6 lines

The /proc/bus/input/devices has an extensible structure. You can just add an "A:" line (for Activity) instead of adding a new proc file.

I know, but IMO there is too much stuff to parse in there. Activity counters are frequently accessed by daemons, and four or five concurrent daemons are the norm in a typical X11 linux box...

Syscalls are fast enough, and the file is _very_ easy (=> fast) to parse.

Quoted 7 lines

Also, the activity counters should IMO coincide with the event times passed through /dev/input/event, and should not be jiffies based. Ideally, both should be based on clock_gettime(CLOCK_MONOTONIC).

In evdev.c do_gettimeofday() is used. Anyway I just need of a monotonic counter, so get_jiffies_64() wouldn't be better? It isn't affected by wrapping issues and it is probably faster than do_gtod().

Quoted 5 lines

Just use same time source rest of inputs already do...

OK, but what about the time-warp problem?. To fix it I need to know when the system goes to sleep/resumes. In SIN I've solved via the platform driver, introducing suspend() resume() callbacks...

Well, you just need to make sure that a resume() actually is a visible event ...

Hello,

the attached patch* introduces activity counters into input device drivers so that a proper user-space daemon leveraging these counters can implement event notification facilities (e.g. screen savers, intrusion detection, etc.) At this purpose, a second patch has been also attached: it provides a working Perl daemon simulating a screen saver activity.

I had submitted something similar a couple of years ago, by way of a kernel module named SIN (http://lkml.org/lkml/2007/1/18/138)

Despite SIN has been properly maintained in this period, it revealed soon some design weaknesses which urged me towards alternative approaches. The resulting patch is quite straightforward yet provides good features, such as:

1) daemons retain the whole control logic

2) daemons are EVIOCGRAB hassle free

3) daemons do not get biased towards a specific environment (e.g. one monitor, one keyboard...)

That's it.

Cheers,
Alessandro

* 2.6.28.1 friendly

==============================================================================

drivers/input/input.c +49 -0
diff -uprN old/drivers/input/input.c new/drivers/input/input.c
@@ -72,6 +72,12 @@ static void input_pass_event(struct inpu
 			     unsigned int type, unsigned int code, int value)
 {
 	struct input_handle *handle;
+	
+	dev->activity = ktime_get();
+
+	if (dev->activity_notifier) {
+		sysfs_notify_dirent(dev->activity_notifier);
+	}
 
 	rcu_read_lock();
 
@@ -1012,11 +1018,25 @@ static ssize_t input_dev_show_modalias(s
 }
 static DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL);
 
+static ssize_t input_dev_show_activity(struct device *dev,
+				       struct device_attribute *attr,
+				       char *buf)
+{
+	struct input_dev *id = to_input_dev(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "A: %Ld\nD: %Ld\n",
+			 ktime_to_ns(id->activity),
+			 ktime_to_us(ktime_sub(ktime_get(), id->activity)));
+}
+
+static DEVICE_ATTR(activity, S_IRUGO, input_dev_show_activity, NULL);
+
 static struct attribute *input_dev_attrs[] = {
 	&dev_attr_name.attr,
 	&dev_attr_phys.attr,
 	&dev_attr_uniq.attr,
 	&dev_attr_modalias.attr,
+	&dev_attr_activity.attr,
 	NULL
 };
 
@@ -1227,10 +1247,34 @@ static int input_dev_uevent(struct devic
 	return 0;
 }
 
+static inline int warp_activity(struct device *dev) 
+{
+	struct input_dev *id = to_input_dev(dev);
+
+	id->activity = ktime_sub(ktime_get(), id->activity);
+	return 0;
+}
+
+int input_dev_suspend(struct device *dev, pm_message_t state)
+{
+	if (state.event & (PM_EVENT_FREEZE|PM_EVENT_SUSPEND)) {
+		(void) warp_activity(dev);
+	}
+
+	return 0;
+}
+
+int input_dev_resume(struct device *dev)
+{
+	return warp_activity(dev);
+}
+
 static struct device_type input_dev_type = {
 	.groups		= input_dev_attr_groups,
 	.release	= input_dev_release,
 	.uevent		= input_dev_uevent,
+	.suspend	= input_dev_suspend,
+	.resume		= input_dev_resume,
 };
 
 struct class input_class = {
@@ -1401,6 +1445,8 @@ int input_register_device(struct input_d
 		dev->name ? dev->name : "Unspecified device", path ? path : "N/A");
 	kfree(path);
 
+	dev->activity_notifier = sysfs_get_dirent(dev->dev.kobj.sd, "activity");
+	
 	error = mutex_lock_interruptible(&input_mutex);
 	if (error) {
 		device_del(&dev->dev);
@@ -1446,6 +1492,9 @@ void input_unregister_device(struct inpu
 
 	mutex_unlock(&input_mutex);
 
+	sysfs_put(dev->activity_notifier);
+	dev->activity_notifier = NULL;
+
 	device_unregister(&dev->dev);
 }
 EXPORT_SYMBOL(input_unregister_device);
include/linux/input.h +3 -0
diff -uprN old/include/linux/input.h new/include/linux/input.h
@@ -1094,6 +1094,9 @@ struct input_dev {
 
 	struct input_handle *grab;
 
+	struct sysfs_dirent *activity_notifier;
+	ktime_t activity;
+	
 	spinlock_t event_lock;
 	struct mutex mutex;
 

==============================================================================

SIN.pl +259 -0

259 lines not on this page · raw message

#32 lore raw

Re: [PATCH] input: Activity counters

In reply to Vojtech Pavlik

Hi. I think to have sorted out every issues at last; maybe you are still interested in merging activity counters.

Best,

Vojtech Pavlik <[email protected]> writes:

Quoted 21 lines · Alessandro Di Marco

Pavel Machek <[email protected]> writes:

Hi!

Quoted 6 lines

The /proc/bus/input/devices has an extensible structure. You can just add an "A:" line (for Activity) instead of adding a new proc file.

I know, but IMO there is too much stuff to parse in there. Activity counters are frequently accessed by daemons, and four or five concurrent daemons are the norm in a typical X11 linux box...

Syscalls are fast enough, and the file is _very_ easy (=> fast) to parse.

Quoted 7 lines

Also, the activity counters should IMO coincide with the event times passed through /dev/input/event, and should not be jiffies based. Ideally, both should be based on clock_gettime(CLOCK_MONOTONIC).

In evdev.c do_gettimeofday() is used. Anyway I just need of a monotonic counter, so get_jiffies_64() wouldn't be better? It isn't affected by wrapping issues and it is probably faster than do_gtod().

Quoted 5 lines

Just use same time source rest of inputs already do...

OK, but what about the time-warp problem?. To fix it I need to know when the system goes to sleep/resumes. In SIN I've solved via the platform driver, introducing suspend() resume() callbacks...

Well, you just need to make sure that a resume() actually is a visible event ...

Hello,

the attached patch* introduces activity counters into input device drivers so that a proper user-space daemon leveraging these counters can implement event notification facilities (e.g. screen savers, intrusion detection, etc.) At this purpose, a second patch has been also attached: it provides a working Perl daemon simulating a screen saver activity.

I had submitted something similar a couple of years ago, by way of a kernel module named SIN (http://lkml.org/lkml/2007/1/18/138)

Despite SIN has been properly maintained in this period, it revealed soon some design weaknesses which urged me towards alternative approaches. The resulting patch is quite straightforward yet provides good features, such as:

1) daemons retain the whole control logic

2) daemons are EVIOCGRAB hassle free

3) daemons do not get biased towards a specific environment (e.g. one monitor, one keyboard...)

That's it.

Cheers,
Alessandro

* 2.6.28.1 friendly

==============================================================================

drivers/input/input.c +49 -0
diff -uprN old/drivers/input/input.c new/drivers/input/input.c
@@ -72,6 +72,12 @@ static void input_pass_event(struct inpu
 			     unsigned int type, unsigned int code, int value)
 {
 	struct input_handle *handle;
+	
+	dev->activity = ktime_get();
+
+	if (dev->activity_notifier) {
+		sysfs_notify_dirent(dev->activity_notifier);
+	}
 
 	rcu_read_lock();
 
@@ -1012,11 +1018,25 @@ static ssize_t input_dev_show_modalias(s
 }
 static DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL);
 
+static ssize_t input_dev_show_activity(struct device *dev,
+				       struct device_attribute *attr,
+				       char *buf)
+{
+	struct input_dev *id = to_input_dev(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "A: %Ld\nD: %Ld\n",
+			 ktime_to_ns(id->activity),
+			 ktime_to_us(ktime_sub(ktime_get(), id->activity)));
+}
+
+static DEVICE_ATTR(activity, S_IRUGO, input_dev_show_activity, NULL);
+
 static struct attribute *input_dev_attrs[] = {
 	&dev_attr_name.attr,
 	&dev_attr_phys.attr,
 	&dev_attr_uniq.attr,
 	&dev_attr_modalias.attr,
+	&dev_attr_activity.attr,
 	NULL
 };
 
@@ -1227,10 +1247,34 @@ static int input_dev_uevent(struct devic
 	return 0;
 }
 
+static inline int warp_activity(struct device *dev) 
+{
+	struct input_dev *id = to_input_dev(dev);
+
+	id->activity = ktime_sub(ktime_get(), id->activity);
+	return 0;
+}
+
+int input_dev_suspend(struct device *dev, pm_message_t state)
+{
+	if (state.event & (PM_EVENT_FREEZE|PM_EVENT_SUSPEND)) {
+		(void) warp_activity(dev);
+	}
+
+	return 0;
+}
+
+int input_dev_resume(struct device *dev)
+{
+	return warp_activity(dev);
+}
+
 static struct device_type input_dev_type = {
 	.groups		= input_dev_attr_groups,
 	.release	= input_dev_release,
 	.uevent		= input_dev_uevent,
+	.suspend	= input_dev_suspend,
+	.resume		= input_dev_resume,
 };
 
 struct class input_class = {
@@ -1401,6 +1445,8 @@ int input_register_device(struct input_d
 		dev->name ? dev->name : "Unspecified device", path ? path : "N/A");
 	kfree(path);
 
+	dev->activity_notifier = sysfs_get_dirent(dev->dev.kobj.sd, "activity");
+	
 	error = mutex_lock_interruptible(&input_mutex);
 	if (error) {
 		device_del(&dev->dev);
@@ -1446,6 +1492,9 @@ void input_unregister_device(struct inpu
 
 	mutex_unlock(&input_mutex);
 
+	sysfs_put(dev->activity_notifier);
+	dev->activity_notifier = NULL;
+
 	device_unregister(&dev->dev);
 }
 EXPORT_SYMBOL(input_unregister_device);
include/linux/input.h +3 -0
diff -uprN old/include/linux/input.h new/include/linux/input.h
@@ -1094,6 +1094,9 @@ struct input_dev {
 
 	struct input_handle *grab;
 
+	struct sysfs_dirent *activity_notifier;
+	ktime_t activity;
+	
 	spinlock_t event_lock;
 	struct mutex mutex;
 

==============================================================================

SIN.pl +259 -0

259 lines not on this page · raw message

#33 lore raw

Re: [PATCH] input: Activity counters

In reply to Vojtech Pavlik

Hi. I think to have sorted out every issues at last; maybe you are still interested in merging activity counters.

Best,

Vojtech Pavlik <[email protected]> writes:

Quoted 21 lines · Alessandro Di Marco

Pavel Machek <[email protected]> writes:

Hi!

Quoted 6 lines

The /proc/bus/input/devices has an extensible structure. You can just add an "A:" line (for Activity) instead of adding a new proc file.

I know, but IMO there is too much stuff to parse in there. Activity counters are frequently accessed by daemons, and four or five concurrent daemons are the norm in a typical X11 linux box...

Syscalls are fast enough, and the file is _very_ easy (=> fast) to parse.

Quoted 7 lines

Also, the activity counters should IMO coincide with the event times passed through /dev/input/event, and should not be jiffies based. Ideally, both should be based on clock_gettime(CLOCK_MONOTONIC).

In evdev.c do_gettimeofday() is used. Anyway I just need of a monotonic counter, so get_jiffies_64() wouldn't be better? It isn't affected by wrapping issues and it is probably faster than do_gtod().

Quoted 5 lines

Just use same time source rest of inputs already do...

OK, but what about the time-warp problem?. To fix it I need to know when the system goes to sleep/resumes. In SIN I've solved via the platform driver, introducing suspend() resume() callbacks...

Well, you just need to make sure that a resume() actually is a visible event ...

Hello,

the attached patch* introduces activity counters into input device drivers so that a proper user-space daemon leveraging these counters can implement event notification facilities (e.g. screen savers, intrusion detection, etc.) At this purpose, a second patch has been also attached: it provides a working Perl daemon simulating a screen saver activity.

I had submitted something similar a couple of years ago, by way of a kernel module named SIN (http://lkml.org/lkml/2007/1/18/138)

Despite SIN has been properly maintained in this period, it revealed soon some design weaknesses which urged me towards alternative approaches. The resulting patch is quite straightforward yet provides good features, such as:

1) daemons retain the whole control logic

2) daemons are EVIOCGRAB hassle free

3) daemons do not get biased towards a specific environment (e.g. one monitor, one keyboard...)

That's it.

Cheers,
Alessandro

* 2.6.28.1 friendly

==============================================================================

drivers/input/input.c +49 -0
diff -uprN old/drivers/input/input.c new/drivers/input/input.c
@@ -72,6 +72,12 @@ static void input_pass_event(struct inpu
 			     unsigned int type, unsigned int code, int value)
 {
 	struct input_handle *handle;
+	
+	dev->activity = ktime_get();
+
+	if (dev->activity_notifier) {
+		sysfs_notify_dirent(dev->activity_notifier);
+	}
 
 	rcu_read_lock();
 
@@ -1012,11 +1018,25 @@ static ssize_t input_dev_show_modalias(s
 }
 static DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL);
 
+static ssize_t input_dev_show_activity(struct device *dev,
+				       struct device_attribute *attr,
+				       char *buf)
+{
+	struct input_dev *id = to_input_dev(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "A: %Ld\nD: %Ld\n",
+			 ktime_to_ns(id->activity),
+			 ktime_to_us(ktime_sub(ktime_get(), id->activity)));
+}
+
+static DEVICE_ATTR(activity, S_IRUGO, input_dev_show_activity, NULL);
+
 static struct attribute *input_dev_attrs[] = {
 	&dev_attr_name.attr,
 	&dev_attr_phys.attr,
 	&dev_attr_uniq.attr,
 	&dev_attr_modalias.attr,
+	&dev_attr_activity.attr,
 	NULL
 };
 
@@ -1227,10 +1247,34 @@ static int input_dev_uevent(struct devic
 	return 0;
 }
 
+static inline int warp_activity(struct device *dev) 
+{
+	struct input_dev *id = to_input_dev(dev);
+
+	id->activity = ktime_sub(ktime_get(), id->activity);
+	return 0;
+}
+
+int input_dev_suspend(struct device *dev, pm_message_t state)
+{
+	if (state.event & (PM_EVENT_FREEZE|PM_EVENT_SUSPEND)) {
+		(void) warp_activity(dev);
+	}
+
+	return 0;
+}
+
+int input_dev_resume(struct device *dev)
+{
+	return warp_activity(dev);
+}
+
 static struct device_type input_dev_type = {
 	.groups		= input_dev_attr_groups,
 	.release	= input_dev_release,
 	.uevent		= input_dev_uevent,
+	.suspend	= input_dev_suspend,
+	.resume		= input_dev_resume,
 };
 
 struct class input_class = {
@@ -1401,6 +1445,8 @@ int input_register_device(struct input_d
 		dev->name ? dev->name : "Unspecified device", path ? path : "N/A");
 	kfree(path);
 
+	dev->activity_notifier = sysfs_get_dirent(dev->dev.kobj.sd, "activity");
+	
 	error = mutex_lock_interruptible(&input_mutex);
 	if (error) {
 		device_del(&dev->dev);
@@ -1446,6 +1492,9 @@ void input_unregister_device(struct inpu
 
 	mutex_unlock(&input_mutex);
 
+	sysfs_put(dev->activity_notifier);
+	dev->activity_notifier = NULL;
+
 	device_unregister(&dev->dev);
 }
 EXPORT_SYMBOL(input_unregister_device);
include/linux/input.h +3 -0
diff -uprN old/include/linux/input.h new/include/linux/input.h
@@ -1094,6 +1094,9 @@ struct input_dev {
 
 	struct input_handle *grab;
 
+	struct sysfs_dirent *activity_notifier;
+	ktime_t activity;
+	
 	spinlock_t event_lock;
 	struct mutex mutex;
 

==============================================================================

SIN.pl +259 -0

259 lines not on this page · raw message