public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Lan Tianyu <tianyu.lan@intel.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Lan Tianyu <tianyu.lan@intel.com>,
	Sarah Sharp <sarah.a.sharp@linux.intel.com>,
	lenb@kernel.org, gregkh@linuxfoundation.org,
	linux-acpi@vger.kernel.org, linux-usb@vger.kernel.org
Subject: Re: [RFC PATCH] usb/acpi: Add support usb port power off mechanism for device fixed on the motherboard
Date: Sat, 12 May 2012 00:16:39 +0800	[thread overview]
Message-ID: <4FAD3B67.2010302@intel.com> (raw)
In-Reply-To: <4FAD3A51.4010803@intel.com>

On 2012年05月12日 00:12, Lan Tianyu wrote:
> hi all:
> 	Great thanks for review.
> On 2012年05月11日 01:44, Alan Stern wrote:
>> On Thu, 10 May 2012, Sarah Sharp wrote:
>>
>>> On Thu, May 10, 2012 at 11:54:04AM -0400, Alan Stern wrote:
>>>> On Thu, 10 May 2012, Lan Tianyu wrote:
>>>>
>>>>> hi all:
>>>>> 	Currently, we are working on usb port power off mechanism. Our developing
>>>>> machine provides usb port power control (a vbus switch)via ACPI power resource.
>>>>> When the power resource turns off, usb port powers off and usb device loses
>>>>> power. From usb hub side, just like the device being unplugged.
>>>>>
>>>>> 	Since usb port power off will affect hot-plug and devices remote wakeup
>>>>> function, it should be careful to do that.
>>>>> 	We conclude three different situations for power off mechanism.
>>>>> 	(1) hard-wired port with device
>>>>> 	(2) hot-pluggable port without device
>>>>> 	(3) hot-pluggable port with device
>>>>>
>>>>> For hard-wired port, the device will not be removed physically. So we can
>>>>> power off it when device is suspended and remote wakeup is disabled without
>>>>> concerning with hot-plug. This patch is dedicated to this siutation.
>>>>>
>>>>> This patch is to provide usb acpi power control method and call them in the
>>>>> usb_port_suspend() and usb_port_resume() when port can be power off. When the
>>>>> usb port is in the power off state, usb core doesn't remove device which is
>>>>> attached to the port. The device is still on the system and user can access
>>>>> the device.
>>>>
>>>> Can you provide any examples where this would be useful?  It won't end
>>>> up saving very much power (although on a laptop even a little bit might
>>>> help).
>>>
>>> Every little bit of power savings helps for the particular system that
>>> implements the USB port power off.  For this particular platform, Intel
>>> is looking at the system as a whole and trying to eek out power savings
>>> where ever they can.  A little power savings in one particular subsystem
>>> may not seem like a big deal, but when you look at the overall picture,
>>> the long tail adds up.  Just trust me, I'm excited about this system. :)
>>
>> I'll take your word for it.  :-)
>>
>      The power saving depends on devices. I test a usb3.0 ssd. The power saving of
> power off is about 2.2w more than just selective suspend. In theory, power
> off can help to save remaining power after selective suspend.
>
>>> As for examples of where the port power off would be useful, think about
>>> a laptop with several internal ports.  The customer can save some money
>>> by choosing not to purchase an internal USB bluetooth device.  The OEM
>>> may have just one motherboard for those two choices, so the port that
>>> would have held the bluetooth device will be empty.  In that case, we'll
>>> never see a USB device connect on that empty port, so we may as well
>>> power it down.  If we can further power off the internal webcam port
>>> when the device is suspended, we can save more power.
>>
>> The patch did not address the case of powering down ports that have no
>> devices attached.  That might be a better place to start, because it's
>> simpler, even though it might not yield as much power savings.
>
> Do you mean internal ports?
>   From my opinion, ACPI will tell us whether the port is connectable or not.
> When the internal port is not connectable, this means the port is not used
> and this patch will power down the port.
>
> @@ -55,9 +81,14 @@ static int usb_acpi_check_port_connect_type(struct usb_device
> *hdev,
>                   pld.user_visible ?
>                       USB_PORT_CONNECT_TYPE_HOT_PLUG :
>                       USB_PORT_CONNECT_TYPE_HARD_WIRED);
> -   else if (!pld.user_visible)
> +   else if (!pld.user_visible) {
>           usb_set_hub_port_connect_type(hdev, port1, USB_PORT_NOT_USED);
>
> +       /* Power off the usb port which may not be used.*/
> +       if (usb_acpi_power_manageable(hdev, port1))
> +           usb_acpi_set_power_state(hdev, port1, false);
> +   }
> +
>
> For external ports, this should be associated with sys file control. The users
> need to determine when they should be power off.
>
> So I should work on the external ports without devices firstly and
> add the sys file for user to control?
>
>>
>> There's one more thing to consider, which was missing from the patch.
>> When you power the port back up and resume the device, it will
>> necessarily be a reset-resume.  You won't want to do this if any of the
>> drivers attached to the device's interfaces doesn't have reset-resume
>> support.
>>
>>> Another example is when a user walks away from their laptop with some
>>> USB devices plugged in.  If userspace can somehow know when the system
>>> is idle (e.g. the screen blanks, the bluetooth/NFC radio no longer
>>> detects the person's phone, etc), we can power off unconnected and
>>> suspended external ports.  The hypothesis is that some users may not
>>> care about USB device connects and disconnects when their system is
>>> idle.  They really will only care that the changes get noticed when
>>> they start using their system.
>>>
>>> This breaks down for some users, of course.  Arjan has several desktops
>>> under his desk that are always on, and he starts interacting with them
>>> by plugging in a USB mouse and keyboard.  So obviously the "port power
>>> off on screen blank" policy might not work for him.  It also won't work
>>> for servers, where no one connects a real monitor to the server for
>>> months, but server folks probably won't care about this mechanism
>>> because their power budget is so much larger.
>>>
>>> However, someone on an airplane, trying to eek out every mW out of their
>>> battery, would want to power off any external unconnected or suspended
>>> USB ports.
>>>
>>> The point is that whether a user wants to allow the ports to be powered
>>> off should be a userspace policy.  That's why we export the sysfs file,
>>> so that desktop software can implement whatever their customers want.
>>> Personally, I would want a checkbox in the Gnome display settings that
>>> says "Power off USB ports on screen blank".
>>
>> Makes sense.  (But I foresee a lot of confusion among users when this
>> box is checked and the ports don't get powered down -- many of
>> today's laptops are incapable of powering down their USB ports.)
>>
> How about to just provide sys files if the usb port can be power off
> and the checkbox only is selectable when sys files exit.
>>>>> "waiting for connection" state is to avoid device to being removed.
>>>>
>>>> Why would the device be removed?
>>>
>>> When we turn the power back on, we'll get a connect status change bit
>>> set.  We don't want the USB core to misinterpret that bit and try to
>>> logically disconnect the device attached to the port.
>>
>> All you have to do is turn off the connect-change status bit.  In fact,
>> the debounce routine does this already.  Just leave the port state set
>> to "off" until the connection is debounced.
> This is my original version. :)
> But after testing, I found that after the connection is debounced,
> hub_port_connect_change() may not to be invoked or not reach place
> "disconnect devices".
>
> hub_port_connect_change() {
> ...
> /* debounce may be completed before here and port's state has becomed
>    * "on". The device also will be removed.
>    */	
> if (hub->port_data[port1 - 1].power_state == USB_PORT_POWER_STATE_OFF) {
> 	clear_bit(port1, hub->change_bits);
> 	return;
> }
> 	
> /* Disconnect any existing devices under this port */
> if (udev)
> 	usb_disconnect(&hub->port_data[port1-1].child);
> clear_bit(port1, hub->change_bits);
>
> ...
> }
>
> I spent a lot of time resolving the problem. At last, I found to add
> "waiting for connection" state to resolve the problem.
>
> After power on the port, hub_irq() invokes kick_khubd() to deal with
> connect or enable change event. Connect debouncing does in the
> usb_port_resume() and  connect-change event is processed in hub_thread().
> It is hard to synchronize them and the port's state should be set to
> "on" after the connect-change event finishing.
>>
>> You may also have to turn off the enable-change status bit.
>>
> You mean clear_port_feature(connect or enable change)?
>   From my opinion, this will be done in the hub_event() since
> hub is active and hub->quiescing should be 0 when the usb_port_resume()
> is invoking. Every portIs that right?
>
>>> What if the external device was suspended, we power off the port, and
>>> then the user yanks the device while it was suspended?  A device may
>>> never connect in that case.
>>
>> Then the debounce loop in usb_port_wait_for_connected() will time out.
>> At that point you'll know the device has been disconnected.
>>
>>> Let me know if you have any more questions about the mechanisms or
>>> policy we're trying to set up.  Tianyu has been creating these patches,
>>> but I've tried to provide some advice to him along the way.
>>
>> I think I get the picture.  It's a tricky job, because you can easily
>> go too far and turn off something that needs to remain on.
> This is reason why
This is why I want to device driver to set can_power_off, driver may know
clear when the device can be power off.
>>
>> Alan Stern
>>
>

-- 
Best Regards
Tianyu Lan
linux kernel enabling team
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2012-05-11 16:21 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-10  8:33 [RFC PATCH] usb/acpi: Add support usb port power off mechanism for device fixed on the motherboard Lan Tianyu
2012-05-10 15:54 ` Alan Stern
     [not found]   ` <Pine.LNX.4.44L0.1205101136470.1831-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-05-10 16:35     ` Sarah Sharp
2012-05-10 17:44       ` Alan Stern
2012-05-11 16:12         ` Lan Tianyu
2012-05-11 16:16           ` Lan Tianyu [this message]
2012-05-11 17:44           ` Alan Stern
2012-05-11 18:12             ` Sarah Sharp
2012-05-12 12:47               ` Sergei Shtylyov
2012-05-12 14:04                 ` Greg KH
2012-05-12 18:00               ` Lan Tianyu
2012-05-11 18:18             ` Lan Tianyu
     [not found]             ` <Pine.LNX.4.44L0.1205111302080.1865-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-05-11 18:35               ` Greg KH
2012-05-11 19:32                 ` Alan Stern
2012-05-11 20:11                 ` Sarah Sharp
2012-05-11 21:09                   ` Peter Stuge
2012-05-15  1:47                     ` Sarah Sharp
2012-05-15  4:57                       ` Peter Stuge
2012-05-11 19:54               ` Lan, Tianyu
2012-05-11 20:15                 ` Sarah Sharp
2012-05-11 20:26                   ` Alan Stern
2012-05-11 20:20                 ` Alan Stern
2012-05-12 17:47                   ` Lan Tianyu
2012-05-12 18:04                     ` Lan Tianyu
2012-05-13  2:50                     ` Alan Stern
2012-05-10 19:19     ` Dan Williams
     [not found]       ` <1336677578.6463.5.camel-wKZy7rqYPVb5EHUCmHmTqw@public.gmane.org>
2012-05-10 21:11         ` Sarah Sharp
2012-05-11  4:13           ` Peter Stuge
2012-05-11 14:20             ` Alan Stern
     [not found]               ` <Pine.LNX.4.44L0.1205111019000.1865-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-05-11 14:30                 ` Peter Stuge
2012-05-11 14:08           ` Alan Stern
2012-05-11 18:03             ` Sarah Sharp
2012-05-11 19:14               ` Alan Stern
2012-05-11 20:21                 ` Sarah Sharp
2012-05-11 20:36                   ` Alan Stern
2012-05-11 23:59                     ` Sarah Sharp
2012-05-12  0:17                       ` Greg KH
2012-05-12 13:54                         ` Alan Stern
2012-05-14 23:21                         ` Sarah Sharp
2012-05-15 14:31                           ` Lan Tianyu
     [not found]                             ` <4FB268CA.9060304-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2012-05-15 15:18                               ` Greg KH
2012-05-15 20:00                                 ` Sarah Sharp
2012-05-16  6:26                                   ` Lan Tianyu
2012-05-16 14:36                                     ` Alan Stern
2012-05-16 14:39                                       ` Greg KH
2012-05-16 14:54                                         ` Lan Tianyu
2012-05-16 15:08                                           ` Greg KH
2012-05-16 15:32                                             ` Lan Tianyu
     [not found]                                             ` <20120516150846.GB3293-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2012-05-16 15:57                                               ` Sarah Sharp
2012-05-16 15:12                                           ` Alan Stern
     [not found]                                         ` <20120516143958.GA612-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2012-05-17 11:42                                           ` Sergei Shtylyov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FAD3B67.2010302@intel.com \
    --to=tianyu.lan@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=sarah.a.sharp@linux.intel.com \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox