Re: Where is PageHead defined in v5.0?

2019-03-27 Thread Valdis Klētnieks
On Wed, 27 Mar 2019 17:23:05 -0700, Igor Pylypiv said:
> and TESTPAGEFLAG defines PageHead:
> #define TESTPAGEFLAG(uname, lname, policy) \
> static __always_inline int Page##uname(struct page *page)
> 
> (https://elixir.bootlin.com/linux/v5.0.5/source/include/linux/page-flags.h#L215)

General tip:  If you're trying to find where the kernel defines FooBar,
and 'git grep FooBar' only finds uses and no definitions, it probably
means somebody got over-exuberant with the ## pre-processor
operator

'git grep Foo##' usually reveals the culprit. ;)

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Where is PageHead defined in v5.0?

2019-03-27 Thread Tobin C. Harding
On Wed, Mar 27, 2019 at 05:23:05PM -0700, Igor Pylypiv wrote:
> On Wed, Mar 27, 2019 at 4:51 PM Tobin C. Harding  wrote:
> >
> > On Wed, Mar 27, 2019 at 07:34:58PM -0500, Jesse Simpson wrote:
> > > Hi Tobin,
> > >
> > > I took a look on my system, and I wasn't able to find where PageHead is
> > > defined either. I used grep to search for it as well as vim with ctags.
> > > Maybe it's hidden away in some built-in.a or binary file.
> >
> > Cheers Jesse, confirmation that I've not gone mad - that's a win.
> >
> > I'll repost this to mm-linux tomorrow if no one on here knows.
> >
> > thanks,
> > Tobin.
> >
> > ___
> > Kernelnewbies mailing list
> > Kernelnewbies@kernelnewbies.org
> > https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> 
> Hi Tobin and Jesse,
> 
> Neither grep nor ctags are going to help you here :)
> 
> PageHead is implicitly defined using macros __PAGEFLAG:
> __PAGEFLAG(Head, head, PF_ANY) CLEARPAGEFLAG(Head, head, PF_ANY)
> 
> (https://elixir.bootlin.com/linux/v5.0.5/source/include/linux/page-flags.h#L517)
> 
> __PAGEFLAG defines TESTPAGEFLAG:
> 
> (https://elixir.bootlin.com/linux/v5.0.5/source/include/linux/page-flags.h#L248)
> 
> and TESTPAGEFLAG defines PageHead:
> #define TESTPAGEFLAG(uname, lname, policy) \
> static __always_inline int Page##uname(struct page *page)
> 
> (https://elixir.bootlin.com/linux/v5.0.5/source/include/linux/page-flags.h#L215)

Thanks Igor.

> See, it is simple :)

hmmm macros - no further comment needed :)


thanks
Tobin

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Where is PageHead defined in v5.0?

2019-03-27 Thread Igor Pylypiv
On Wed, Mar 27, 2019 at 4:51 PM Tobin C. Harding  wrote:
>
> On Wed, Mar 27, 2019 at 07:34:58PM -0500, Jesse Simpson wrote:
> > Hi Tobin,
> >
> > I took a look on my system, and I wasn't able to find where PageHead is
> > defined either. I used grep to search for it as well as vim with ctags.
> > Maybe it's hidden away in some built-in.a or binary file.
>
> Cheers Jesse, confirmation that I've not gone mad - that's a win.
>
> I'll repost this to mm-linux tomorrow if no one on here knows.
>
> thanks,
> Tobin.
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Hi Tobin and Jesse,

Neither grep nor ctags are going to help you here :)

PageHead is implicitly defined using macros __PAGEFLAG:
__PAGEFLAG(Head, head, PF_ANY) CLEARPAGEFLAG(Head, head, PF_ANY)

(https://elixir.bootlin.com/linux/v5.0.5/source/include/linux/page-flags.h#L517)

__PAGEFLAG defines TESTPAGEFLAG:

(https://elixir.bootlin.com/linux/v5.0.5/source/include/linux/page-flags.h#L248)

and TESTPAGEFLAG defines PageHead:
#define TESTPAGEFLAG(uname, lname, policy) \
static __always_inline int Page##uname(struct page *page)

(https://elixir.bootlin.com/linux/v5.0.5/source/include/linux/page-flags.h#L215)

See, it is simple :)

Thanks,
Igor

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Where is PageHead defined in v5.0?

2019-03-27 Thread Tobin C. Harding
On Wed, Mar 27, 2019 at 07:34:58PM -0500, Jesse Simpson wrote:
> Hi Tobin,
> 
> I took a look on my system, and I wasn't able to find where PageHead is
> defined either. I used grep to search for it as well as vim with ctags.
> Maybe it's hidden away in some built-in.a or binary file.

Cheers Jesse, confirmation that I've not gone mad - that's a win.

I'll repost this to mm-linux tomorrow if no one on here knows.

thanks,
Tobin.

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Where is PageHead defined in v5.0?

2019-03-27 Thread Jesse Simpson
Hi Tobin,

I took a look on my system, and I wasn't able to find where PageHead is
defined either. I used grep to search for it as well as vim with ctags.
Maybe it's hidden away in some built-in.a or binary file.

I'm looking on version 5.0.0.

Good luck,

Jesse Simpson


On Thu, Mar 28, 2019 at 09:26:15AM +1100, Tobin C. Harding wrote:
> Hi,
> 
> I cannot locate the definition of PageHead?  It seems to have
> disappeared after v4.0?  I can see it defined as a function here:
> 
>   
> https://elixir.bootlin.com/linux/v4.0/source/include/linux/page-flags.h#L401
> 
> But on the mainline (v5.1-rc2) I get:
> 
> $ git grep ' PageHead'
> include/linux/page-flags.h:int PageHeadHuge(struct page *page);
> include/linux/page-flags.h:   return PageHead(page);
> include/linux/page-flags.h:   return PageHead(page) && 
> test_bit(PG_double_map, [1].flags);
> mm/hugetlb.c: return PageHead(page) && PagePrivate([1]);
> mm/hugetlb.c: * PageHeadHuge() only returns true for hugetlbfs head page, but 
> not for
> mm/hugetlb.c:int PageHeadHuge(struct page *page_head)
> 
> Clearly it is defined _somewhere_.   Anyone any idea what brain
> dysfunction I am having right now?
> 
> thanks,
> Tobin.
> 
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Where is PageHead defined in v5.0?

2019-03-27 Thread Tobin C. Harding
Hi,

I cannot locate the definition of PageHead?  It seems to have
disappeared after v4.0?  I can see it defined as a function here:


https://elixir.bootlin.com/linux/v4.0/source/include/linux/page-flags.h#L401

But on the mainline (v5.1-rc2) I get:

$ git grep ' PageHead'
include/linux/page-flags.h:int PageHeadHuge(struct page *page);
include/linux/page-flags.h: return PageHead(page);
include/linux/page-flags.h: return PageHead(page) && 
test_bit(PG_double_map, [1].flags);
mm/hugetlb.c:   return PageHead(page) && PagePrivate([1]);
mm/hugetlb.c: * PageHeadHuge() only returns true for hugetlbfs head page, but 
not for
mm/hugetlb.c:int PageHeadHuge(struct page *page_head)

Clearly it is defined _somewhere_.   Anyone any idea what brain
dysfunction I am having right now?

thanks,
Tobin.

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Unexpected scheduling with mutexes

2019-03-27 Thread Martin Christian
Hi,

I've written a linux kernel module for an USB device. The USB driver
provides 2 read-only character devices, which can be opened only
exclusively by one process:
 - `/dev/cdev_a`
 - `/dev/cdev_b`

The USB device can only handle one request at a time.

The test setup is a follows:
 - Processes A reads data from 1st device: `dd if=/dev/cdev_a of=/tmp/a
bs=X`
 - Processes B reads data from 2nd device: `dd if=/dev/cdev_b of=/tmp/b
bs=X`
 - Process A and B run in parallel
 - After 10 seconds both processes are killed and size of both output
files is compared.

For certain values of `X` there is a significant difference in size
between the two files, which I don't expect.

A read call to the driver does the following:
 1. `mutex_lock_interruptible(iolock)`
 2. `usb_bulk_msg(dev, pipe, buf, X, timeout)`
 3. `mutex_unlock(iolock)`
 4. `copy_to_user(buf)`

What I would expect is the following:
 1. Proc A: `mutex_lock_interruptible(iolock)`
 2. Proc A: `usb_bulk_msg(dev, pipe, buf, X, timeout)`
 3. Scheduling: A -> B
 4. Proc B: `mutex_lock_interruptible(iolock)` -> blocks
 5. Scheduling: B -> A
 6. Proc A: `mutex_unlock(iolock)`
 7. Proc A: `copy_to_user(buf)`
 8. Proc A: `mutex_lock_interruptible(iolock)` -> blocks
 9. Scheduling: A -> B
 10. Proc B: `usb_bulk_msg(dev, pipe, buf, X, timeout)`

But what I see with ftrace is that in step 8, process A still continues.
And it seems that for certain values of X the time inside the critical
region is a multiple of the time slice, so that process B always gets
the time slice when the critical region is blocked. What would be a best
practise solution for this? I was thinking of calling `schedule()` each
time after copying to user space or playing with nice values or using
wait_queues?

-- 
Dipl.-Inf. Martin Christian
Senior Berater Entwicklung Hardware
secunet Security Networks AG

Tel.: +49 201 5454-3612, Fax +49 201 5454-1323
E-Mail: martin.christ...@secunet.com
Ammonstraße 74, 01067 Dresden
www.secunet.com





signature.asc
Description: OpenPGP digital signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies