mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tomas Winkler <tomasw@gmail.com>
To: Greg KH <greg@kroah.com>
Cc: Johannes Berg <johannes@sipsolutions.net>,
	Kay Sievers <kay.sievers@vrfy.org>,
	David Woodhouse <dwmw2@infradead.org>,
	"Rafael J. Wysocki" <rjw@sisk.pl>,
	Emmanuel Grumbach <egrumbach@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: request_firmware API exhaust memory
Date: Thu, 22 Apr 2010 01:22:51 +0300	[thread overview]
Message-ID: <t2w1ba2fa241004211522le49fc938m341553b0f2b89031@mail.gmail.com> (raw)
In-Reply-To: <20100419145934.GA10893@kroah.com>

[-- Attachment #1: Type: text/plain, Size: 1105 bytes --]

On Mon, Apr 19, 2010 at 5:59 PM, Greg KH <greg@kroah.com> wrote:
> On Mon, Apr 19, 2010 at 03:20:34PM +0300, Tomas Winkler wrote:
>> Lately we've been developing a device that rather more extensively
>> used request_firmware API in load and also using pm_notifiers to load
>> firmware.
>
> Do you have a pointer to your driver source anywhere that shows how you
> are trying to use the firmware api in this manner?

I've attached a very simple  test driver I'm using.  Just wanted to
eliminate anything else.
Bellow is a little script that loads and releases the firmware. My
previous observation was wrong.
The free memory gradually decreases regardless of number or dangling
udevd forks, which are eventually collected if the sleep period is
long enough ~10s.

testfw=${1:-test-fw600k.fw}
count=${2:-100}
s=${3:-10}
for ((i=0; i<$count ; i++)) ; do
        echo -n $testfw > /sys/devices/platform/fw-test/load_fw
        echo -n 1 > /sys/devices/platform/fw-test/release_fw
        sleep $s
        grep MemFree /proc/meminfo | awk '{print $2}'
        ps auxwww | grep udevd | wc -l
done

Thanks
Tomas

[-- Attachment #2: fw-test.c --]
[-- Type: application/octet-stream, Size: 3305 bytes --]

/*
 *  fw-test.c -FW Test Driver
 *
 *
 *  Copyright (C) 2010, Intel Corporation. All rights reserved.
 *
 *  This program 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; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *
 *  TODO
 *
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/proc_fs.h>
#include <linux/backlight.h>
#include <linux/platform_device.h>
#include <linux/sysfs.h>
#include <linux/firmware.h>


MODULE_AUTHOR("Tomas Winkler");
MODULE_DESCRIPTION("Firmware API Test Driver");
MODULE_LICENSE("GPL");

struct fw_test_dev {
	struct platform_device *p_dev;
	struct mutex mutex;
	const struct firmware *fw;
};

static struct fw_test_dev fw_test;

static ssize_t load_fw(struct device *d, struct device_attribute *attr,
		const char *buf, size_t count)
{
	struct fw_test_dev *priv = &fw_test;
	ssize_t ret;

	mutex_lock(&fw_test.mutex);
	ret = request_firmware(&priv->fw, buf, d);
	if (ret)
		printk(KERN_ERR "request fail %s ret=%zd", buf, ret);
	else 
		ret = count;
	mutex_unlock(&fw_test.mutex);

	printk(KERN_INFO "FW-TEST LOAD");
	return ret;
}

static ssize_t release_fw(struct device *d, struct device_attribute *attr,
		const char *buf, size_t count)
{
	struct fw_test_dev *priv = &fw_test;
	
	mutex_lock(&fw_test.mutex);
	release_firmware(priv->fw);
	priv->fw = NULL;
	mutex_unlock(&fw_test.mutex);
	printk(KERN_INFO "FW-TEST RELEASE");
	
	return count;
}

static DEVICE_ATTR(load_fw, S_IWUGO, NULL, load_fw);

static DEVICE_ATTR(release_fw, S_IWUGO, NULL, release_fw);

static struct attribute *fw_test_sysfs_entries[] = {
	&dev_attr_load_fw.attr,
	&dev_attr_release_fw.attr,
	NULL
};

static struct attribute_group fw_test_attribute_group = {
	.name = NULL,		/* put in device directory */
	.attrs = fw_test_sysfs_entries,
};

static void fw_test_exit(void)
{

	sysfs_remove_group(&fw_test.p_dev->dev.kobj, &fw_test_attribute_group);
	platform_device_unregister(fw_test.p_dev);
	printk(KERN_INFO "FW API Test Driver Unloaded");

	return;
}

static int __init fw_test_init(void)
{

	int ret;

	mutex_init(&fw_test.mutex);

	fw_test.p_dev = platform_device_register_simple("fw-test", -1, NULL, 0);
	if (IS_ERR(fw_test.p_dev)) {
		ret = PTR_ERR(fw_test.p_dev);
		printk(KERN_ERR "unable to register platform device\n");
		fw_test.p_dev = NULL;
		fw_test_exit();
		return ret;
	}
	ret = sysfs_create_group(&fw_test.p_dev->dev.kobj, &fw_test_attribute_group);
	if (ret) {
		printk(KERN_ERR "Failed to allocate SYSFS entry");
		fw_test.p_dev = NULL;
		fw_test_exit();
		return ret;
	}
	printk(KERN_INFO "FW API Test Driver Loaded");
	return 0;

}

module_init(fw_test_init);
module_exit(fw_test_exit);

  reply	other threads:[~2010-04-21 22:22 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-19 12:20 Tomas Winkler
2010-04-19 12:35 ` Kay Sievers
2010-04-19 14:59 ` Greg KH
2010-04-21 22:22   ` Tomas Winkler [this message]
2010-04-25 16:37     ` Greg KH
2010-04-25 19:22       ` Tomas Winkler
2010-04-25 19:36         ` Greg KH
2010-04-25 20:09           ` Tomas Winkler
2010-04-26 10:38             ` Kay Sievers
2010-04-26 15:19               ` Kay Sievers
2010-04-26 16:59                 ` Tomas Winkler
2010-04-27  4:12                 ` Sujith Manoharan
2010-04-27 11:18                 ` Tomas Winkler
2010-04-27 11:53                   ` Tomas Winkler
2010-04-27 12:05                   ` Kay Sievers
2010-04-27 12:43                     ` David Woodhouse
2010-04-27 13:34                       ` Kay Sievers
2010-04-28  8:23                         ` Kay Sievers
2010-04-28 13:07                           ` Tomas Winkler

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=t2w1ba2fa241004211522le49fc938m341553b0f2b89031@mail.gmail.com \
    --to=tomasw@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=egrumbach@gmail.com \
    --cc=greg@kroah.com \
    --cc=johannes@sipsolutions.net \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rjw@sisk.pl \
    /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

all inboxes | Powered by JetHome®