Re: copy offload (copy_file_range) and sendfile()

2016-03-21 Thread Manoj Nayak
1.
sendfile() and splice uses temporary buffer in terms of pipe.

do_splice_direct(in.file, , out.file, _pos, count, fl) ->
splice_direct_to_actor(struct file *in, struct splice_desc *sd,
splice_direct_actor *actor)

http://lxr.free-electrons.com/source/fs/splice.c#L602

default_file_splice_read() allocates a page, read data for file1 from disk
to the page, then write the page to a pipe.

default_file_splice_write() reads from the pipe, writes to a page, then
write page to the file2.

So this is not a zero-copy in kernel. This can be a zero-copy from
userspace point of view as we are not doing copy to userspace. but still a
copy is involved a we are doing write to temporary buffer, for example:
pipe.


2.
if copy_file_range() is defined for a filesystem operation then splice is
not used. otherwise
copy_file_range() uses splice method of temporary buffer in terms of a pipe.

http://lxr.free-electrons.com/source/fs/read_write.c#L1412

ret = file_out->f_op->copy_file_range(file_in, pos_in, file_out,
1413   pos_out, len,
flags);
1414 if (ret == -EOPNOTSUPP)
1415 ret = do_splice_direct(file_in, _in, file_out,
_out,
1416 len > MAX_RW_COUNT ? MAX_RW_COUNT :
len, 0);
1417

copy_file_range() does the following things that is much better method than
splice.

COPY_FR_COPY means to copy the data normally, accelerating the work at the
filesystem level if possible.

COPY_FR_REFLINK asks for the destination file to refer to the existing
copy of the data without actually
copying it. Some filesystems (Btrfs, for example) are able to share
references to file blocks in this way.

COPY_FR_DEDUP is like COPY_FR_REFLINK, but it only succeeds if the
destination range already contains  the same data as the source. The end
result is files that look the same as before, but which are now sharing the
data on-disk. It is thus a way of removing blocks of duplicated data within
the filesystem.

The COPY_FR_COPY operation will, in the absence of filesystem-level
acceleration, copy the data directly through the kernel page cache; it is
essentially a splice() operation. Copying through the page cache in this
way is clearly more efficient than doing the copy in user space, since it
avoids the need to copy the data out of the kernel and back in again. If
possible, of course, copying with COPY_FR_REFLINK will be the most
efficient approach.


copy_file_range() does not do the copy. It does a clone of a range of
blocks of a file.


2921 const struct file_operations btrfs_file_operations = {
2922...
2935 .copy_file_range = btrfs_copy_file_range,
2936 .clone_file_range = btrfs_clone_file_range,
2937 .dedupe_file_range = btrfs_dedupe_file_range,
2938 };

3902 ssize_t btrfs_copy_file_range(struct file *file_in, loff_t pos_in,
3903   struct file *file_out, loff_t pos_out,
3904   size_t len, unsigned int flags)
3905 {
3906 ssize_t ret;
3907
3908 ret = btrfs_clone_files(file_out, file_in, pos_in, len,
pos_out);
3909 if (ret == 0)
3910 ret = len;
3911 return ret;
3912 }

Regards
Manoj Nayak
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Attach my own pid

2016-03-21 Thread Pranay Srivastava
On Mon, Mar 21, 2016 at 4:34 PM, Nitin Varyani  wrote:
> struct task_struct {
> volatile long state;
> void *stack;
> ...
> pid_t pid;
> ...
> }
> You mean to say that just mapping the pid_t pid  will do the job. Does the
> linux kernel not store pid somewhere else while forking a child?

No I mean you can translate the pid chosen by kernel and then have a
policy to map it within your framework. That just translates onto a
possible different pid or may be same on another node. That way your
framework goes independent of what the kernel is doing.

Like for example nfs, translates the inode to a file handle internally
but that framework is independent of what happens on both nodes.

>
> On Mon, Mar 21, 2016 at 4:18 PM, Pranay Srivastava 
> wrote:
>>
>> Nitin,
>>
>>
>> On Mon, Mar 21, 2016 at 4:03 PM, Nitin Varyani 
>> wrote:
>> > .Continued That is, if kernel at Computer 2 finds that pid of a
>> > process requesting a system call is 1500, the request is forwarded to
>> > slave
>> > daemon which in turn contacts with the master daemon. Master daemon
>> > requests
>> > the kernel for the system call and sends the result back to slave
>> > daemon.
>>
>> I don't think doing this by pid is better. It might suit you currently
>> but in the long run?
>> If you are able to send the whole context, why not map that pid to
>> your context internally instead of relying
>> on pid which is also visible outside your context.
>>
>> >
>> > On Mon, Mar 21, 2016 at 4:01 PM, Nitin Varyani
>> > 
>> > wrote:
>> >>
>> >> I am trying to create a distributed pid space.
>> >>
>> >> 0 to 2000 Computer 1
>> >> 2001 to 4000 Computer 2
>> >> 4001 to 6000 Computer 3
>> >>
>>
>> your pid 2000 shouldn't have to be same pid 2000 on another node. You
>> just need the context right?
>>
>> >> and so on...
>> >>
>> >> I am running a master user-level process at Computer 1 which sends a
>> >> process context like code, data, registers, PC, etc as well as "pid" to
>> >> slave processes running at other computers. The responsibility of the
>> >> slave
>> >> process is to fork a new process on order of master process and attach
>> >> "pid"
>> >> given by the master to the new process it has forked. Any system call
>> >> on
>> >> slave nodes will have an initial check of " Whether the process belongs
>> >> to
>> >> local node or to the master node?". That is, if kernel at Computer 2
>> >> pid of
>> >> the process is 1500
>> >>
>> >>
>> >>
>> >> On Mon, Mar 21, 2016 at 12:23 PM,  wrote:
>> >>>
>> >>> On Mon, 21 Mar 2016 10:33:44 +0530, Nitin Varyani said:
>> >>>
>> >>> > Sub-task 1: Until now, parent process cannot control the pid of the
>> >>> > forked
>> >>> > child. A pid gets assigned as a sequential number by the kernel at
>> >>> > the
>> >>> > time
>> >>> > the process is forked . I want to modify kernel in such a way that
>> >>> > parent
>> >>> > process can control the pid of the forked child.
>> >>>
>> >>> What does controlling the pid gain you?  To what purpose?
>> >>>
>> >>> > Sub-task 2: On Linux, you can find the maximum PID value for your
>> >>> > system
>> >>> > with the following command:
>> >>> >
>> >>> > $ cat /proc/sys/kernel/pid_max
>> >>> >
>> >>> > Suppose pid_max=2000 for a system. I want that the parent process
>> >>> > should be
>> >>> > able to assign a pid which is greater that 2000 to the forked child.
>> >>>
>> >>> Again, why would you want to do that?
>> >>>
>> >>> Anyhow...
>> >>>
>> >>> echo 3000 > /proc/sys/kernel/pid_max
>> >>> fork a process that gets a pid over 2000.
>> >>>
>> >>> Done.
>> >>>
>> >>> Note that on 32 bit systems, using a pid_max of over 32768 will cause
>> >>> various things in /proc to blow up.
>> >>>
>> >>> I suspect that you need to think harder about what problem you're
>> >>> actually
>> >>> trying to solve here - what will you do with a controlled child PID?
>> >>> Why
>> >>> does
>> >>> it even matter?
>> >>
>> >>
>> >
>> >
>> > ___
>> > Kernelnewbies mailing list
>> > Kernelnewbies@kernelnewbies.org
>> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>> >
>>
>>
>>
>> --
>> ---P.K.S
>
>



-- 
---P.K.S

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


Re: "kdumpbase" dracut module

2016-03-21 Thread Freeman Zhang
On 3/21/16 9:55 PM, Ronit Halder wrote:
> Thanks for helping
> 
> So, this module is used to dump the crash kernel.
> Am I right?
> If not then can you explain how kdump kernel calls the makedumpfile?
> 

You are absolutely right Ronit. By the time the second kernel is booted,
this module will start a service called kdump-capture, which will
execute kdump.sh, which will invoke makedumpfile after all, depending on
your kdump configuration.

All the best!
Freeman



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


Get sk PID from netfilter target

2016-03-21 Thread Sargun Dhillon
I'm attempting to set the mark of a packet based on the PID it was
originated from in the kernel. I came up with the following code as I
was trying to work through things, and I had setup the rule on the
OUTPUT chain:

static unsigned int

static unsigned int

pidmark_tg(struct sk_buff *skb, const struct xt_action_param *par)
{
  struct file *filp;
  if (skb->sk == NULL || skb->sk->sk_socket == NULL) {
skb->mark = 0;
printk("Socket not local, not setting mark?\n");
return XT_CONTINUE;
  }
  filp = skb->sk->sk_socket->file;
  if (filp == NULL)
  {
printk("Filp null. :|\n");
return XT_CONTINUE;
  }
  read_lock(>f_owner.lock);
  const struct cred *cred = filp->f_cred;
  printk("Uid: %d\n", from_kuid_munged(_user_ns, cred->fsuid));
  struct task_struct *task;
  printk("Pid: %d\n", pid_nr(filp->f_owner.pid));
  task = pid_task(filp->f_owner.pid, filp->f_owner.pid_type);
  printk("Task: %x\n", task);
  read_unlock(>f_owner.lock);
  return XT_CONTINUE;
}

Unfortunately, looking at the log, pid always is set to 0, and
pid_task always return null. Is there any way I can fetch the pid that
created the skb from a netfilter target?

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


Re: Linux Kernel Group Scheduling Feature of CFS

2016-03-21 Thread Ruben Safir
On 03/21/2016 12:42 PM, SUNITA wrote:
> Hello,
> I want to test the properties of CFS scheduler on a beaglebone.
> 

This is extremely documented and a subject of nearly every graduate
school and undergrad OS class and thesis.  I don't think your
understanding how it works and I suggest you research this FIRST and
reviewing the source code PRIOR to coming to the mailing list and
begging for help.

Also, make sure you search usenet archives.

Then if you have a specific question, you can frame a good question.

Good luck

Reuvain Safir



-- 
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com

DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013

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


Re: "kdumpbase" dracut module

2016-03-21 Thread Ronit Halder
Thanks for helping

So, this module is used to dump the crash kernel.
Am I right?
If not then can you explain how kdump kernel calls the makedumpfile?

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


Re: "kdumpbase" dracut module

2016-03-21 Thread Dave Young
On 03/19/16 at 12:59pm, Ronit Halder wrote:
> I want to know what is the job of "kdumpbase" dracut module.

Suppose you are using Fedora or RHEL, it is a out of tree module for creating
kdump initramfs. Fedora package kexec-tools will install it to dracut module
directory.

Thanks
Dave

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


PR Value in the top command

2016-03-21 Thread Vishwas Srivastava
Hi All,
i was trying to understand the the meaning of the PR field in
the "top" command.

PR field is the kernel notion of importance of a task.
It is loosely coupled with the "nice" value, which is a user-space concept.
Roughly they are related with..

PR=20+nice   (-20<= nice <=19)
which means, PR can never go below 0.

As an experiment to understand this even more, i created an user-app with
real-time scheduling policy (SCHED_FIFO) and ran this application.

while the application was running i triggerred "top" and what i see that
the PR value for my application displays a -ve value.
what does this mean.
If at all this is correct, what are the valid range of PR which i should
expect?
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Attach my own pid

2016-03-21 Thread Nitin Varyani
struct task_struct {
volatile long state;
void *stack;
...
*pid_t pid;*
...
}
You mean to say that just mapping the *pid_t pid*  will do the job. Does
the linux kernel not store pid somewhere else while forking a child?

On Mon, Mar 21, 2016 at 4:18 PM, Pranay Srivastava 
wrote:

> Nitin,
>
>
> On Mon, Mar 21, 2016 at 4:03 PM, Nitin Varyani 
> wrote:
> > .Continued That is, if kernel at Computer 2 finds that pid of a
> > process requesting a system call is 1500, the request is forwarded to
> slave
> > daemon which in turn contacts with the master daemon. Master daemon
> requests
> > the kernel for the system call and sends the result back to slave daemon.
>
> I don't think doing this by pid is better. It might suit you currently
> but in the long run?
> If you are able to send the whole context, why not map that pid to
> your context internally instead of relying
> on pid which is also visible outside your context.
>
> >
> > On Mon, Mar 21, 2016 at 4:01 PM, Nitin Varyani  >
> > wrote:
> >>
> >> I am trying to create a distributed pid space.
> >>
> >> 0 to 2000 Computer 1
> >> 2001 to 4000 Computer 2
> >> 4001 to 6000 Computer 3
> >>
>
> your pid 2000 shouldn't have to be same pid 2000 on another node. You
> just need the context right?
>
> >> and so on...
> >>
> >> I am running a master user-level process at Computer 1 which sends a
> >> process context like code, data, registers, PC, etc as well as "pid" to
> >> slave processes running at other computers. The responsibility of the
> slave
> >> process is to fork a new process on order of master process and attach
> "pid"
> >> given by the master to the new process it has forked. Any system call on
> >> slave nodes will have an initial check of " Whether the process belongs
> to
> >> local node or to the master node?". That is, if kernel at Computer 2
> pid of
> >> the process is 1500
> >>
> >>
> >>
> >> On Mon, Mar 21, 2016 at 12:23 PM,  wrote:
> >>>
> >>> On Mon, 21 Mar 2016 10:33:44 +0530, Nitin Varyani said:
> >>>
> >>> > Sub-task 1: Until now, parent process cannot control the pid of the
> >>> > forked
> >>> > child. A pid gets assigned as a sequential number by the kernel at
> the
> >>> > time
> >>> > the process is forked . I want to modify kernel in such a way that
> >>> > parent
> >>> > process can control the pid of the forked child.
> >>>
> >>> What does controlling the pid gain you?  To what purpose?
> >>>
> >>> > Sub-task 2: On Linux, you can find the maximum PID value for your
> >>> > system
> >>> > with the following command:
> >>> >
> >>> > $ cat /proc/sys/kernel/pid_max
> >>> >
> >>> > Suppose pid_max=2000 for a system. I want that the parent process
> >>> > should be
> >>> > able to assign a pid which is greater that 2000 to the forked child.
> >>>
> >>> Again, why would you want to do that?
> >>>
> >>> Anyhow...
> >>>
> >>> echo 3000 > /proc/sys/kernel/pid_max
> >>> fork a process that gets a pid over 2000.
> >>>
> >>> Done.
> >>>
> >>> Note that on 32 bit systems, using a pid_max of over 32768 will cause
> >>> various things in /proc to blow up.
> >>>
> >>> I suspect that you need to think harder about what problem you're
> >>> actually
> >>> trying to solve here - what will you do with a controlled child PID?
> Why
> >>> does
> >>> it even matter?
> >>
> >>
> >
> >
> > ___
> > Kernelnewbies mailing list
> > Kernelnewbies@kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >
>
>
>
> --
> ---P.K.S
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Attach my own pid

2016-03-21 Thread Nitin Varyani
A representative process, that is, a process without any user stack,
register values, PC, etc, with *"pid" *is maintained at the master node.
Now, the process which was migrated to a remote node, in this example
Computer 2, and having process id *"pid", *decides to fork(). It is a
system call and is forwarded in the same way to master process. This
request is forwarded to the representative process with process id *"pid"*.
The representative process forks() leading to a new representative process
with process id *"cpid". *This "cpid" is forwarded to master process which
forwards it to slave process. The slave process forwards *"cpid"* to the
remote process with process id *"pid"*. The remote process with process id
*"pid"* now forks a child and attaches *"cpid" * to its child.

This is overview of what I want to achieve. A small correction in my last
mail.

.Continued That is, if kernel at Computer 2 finds that pid of a
process requesting a system call is 1500, the request is forwarded to slave
daemon which in turn contacts with the master daemon. Master daemon
forwards this information to corresponding representative process which
requests the kernel for the system call and sends the result back to slave
daemon.

On Mon, Mar 21, 2016 at 4:03 PM, Nitin Varyani 
wrote:

> .Continued That is, if kernel at Computer 2 finds that pid of a
> process requesting a system call is 1500, the request is forwarded to slave
> daemon which in turn contacts with the master daemon. Master daemon
> requests the kernel for the system call and sends the result back to slave
> daemon.
>
> On Mon, Mar 21, 2016 at 4:01 PM, Nitin Varyani 
> wrote:
>
>> I am trying to create a distributed pid space.
>>
>> 0 to 2000 Computer 1
>> 2001 to 4000 Computer 2
>> 4001 to 6000 Computer 3
>>
>> and so on...
>>
>> I am running a master user-level process at Computer 1 which sends a
>> process context like code, data, registers, PC, etc as well as *"pid"*
>> to slave processes running at other computers. The responsibility of the
>> slave process is to fork a new process on order of master process and
>> attach *"pid" *given by the master to the new process it has forked. Any
>> system call on slave nodes will have an initial check of " Whether the
>> process belongs to local node or to the master node?". That is, if kernel
>> at Computer 2 pid of the process is 1500
>>
>>
>>
>> On Mon, Mar 21, 2016 at 12:23 PM,  wrote:
>>
>>> On Mon, 21 Mar 2016 10:33:44 +0530, Nitin Varyani said:
>>>
>>> > Sub-task 1: Until now, parent process cannot control the pid of the
>>> forked
>>> > child. A pid gets assigned as a sequential number by the kernel at the
>>> time
>>> > the process is forked . I want to modify kernel in such a way that
>>> parent
>>> > process can control the pid of the forked child.
>>>
>>> What does controlling the pid gain you?  To what purpose?
>>>
>>> > Sub-task 2: On Linux, you can find the maximum PID value for your
>>> system
>>> > with the following command:
>>> >
>>> > $ cat /proc/sys/kernel/pid_max
>>> >
>>> > Suppose pid_max=2000 for a system. I want that the parent process
>>> should be
>>> > able to assign a pid which is greater that 2000 to the forked child.
>>>
>>> Again, why would you want to do that?
>>>
>>> Anyhow...
>>>
>>> echo 3000 > /proc/sys/kernel/pid_max
>>> fork a process that gets a pid over 2000.
>>>
>>> Done.
>>>
>>> Note that on 32 bit systems, using a pid_max of over 32768 will cause
>>> various things in /proc to blow up.
>>>
>>> I suspect that you need to think harder about what problem you're
>>> actually
>>> trying to solve here - what will you do with a controlled child PID? Why
>>> does
>>> it even matter?
>>>
>>
>>
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Attach my own pid

2016-03-21 Thread Nitin Varyani
.Continued That is, if kernel at Computer 2 finds that pid of a
process requesting a system call is 1500, the request is forwarded to slave
daemon which in turn contacts with the master daemon. Master daemon
requests the kernel for the system call and sends the result back to slave
daemon.

On Mon, Mar 21, 2016 at 4:01 PM, Nitin Varyani 
wrote:

> I am trying to create a distributed pid space.
>
> 0 to 2000 Computer 1
> 2001 to 4000 Computer 2
> 4001 to 6000 Computer 3
>
> and so on...
>
> I am running a master user-level process at Computer 1 which sends a
> process context like code, data, registers, PC, etc as well as *"pid"* to
> slave processes running at other computers. The responsibility of the slave
> process is to fork a new process on order of master process and attach *"pid"
> *given by the master to the new process it has forked. Any system call on
> slave nodes will have an initial check of " Whether the process belongs to
> local node or to the master node?". That is, if kernel at Computer 2 pid of
> the process is 1500
>
>
>
> On Mon, Mar 21, 2016 at 12:23 PM,  wrote:
>
>> On Mon, 21 Mar 2016 10:33:44 +0530, Nitin Varyani said:
>>
>> > Sub-task 1: Until now, parent process cannot control the pid of the
>> forked
>> > child. A pid gets assigned as a sequential number by the kernel at the
>> time
>> > the process is forked . I want to modify kernel in such a way that
>> parent
>> > process can control the pid of the forked child.
>>
>> What does controlling the pid gain you?  To what purpose?
>>
>> > Sub-task 2: On Linux, you can find the maximum PID value for your system
>> > with the following command:
>> >
>> > $ cat /proc/sys/kernel/pid_max
>> >
>> > Suppose pid_max=2000 for a system. I want that the parent process
>> should be
>> > able to assign a pid which is greater that 2000 to the forked child.
>>
>> Again, why would you want to do that?
>>
>> Anyhow...
>>
>> echo 3000 > /proc/sys/kernel/pid_max
>> fork a process that gets a pid over 2000.
>>
>> Done.
>>
>> Note that on 32 bit systems, using a pid_max of over 32768 will cause
>> various things in /proc to blow up.
>>
>> I suspect that you need to think harder about what problem you're actually
>> trying to solve here - what will you do with a controlled child PID? Why
>> does
>> it even matter?
>>
>
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Attach my own pid

2016-03-21 Thread Nitin Varyani
I am trying to create a distributed pid space.

0 to 2000 Computer 1
2001 to 4000 Computer 2
4001 to 6000 Computer 3

and so on...

I am running a master user-level process at Computer 1 which sends a
process context like code, data, registers, PC, etc as well as *"pid"* to
slave processes running at other computers. The responsibility of the slave
process is to fork a new process on order of master process and attach *"pid"
*given by the master to the new process it has forked. Any system call on
slave nodes will have an initial check of " Whether the process belongs to
local node or to the master node?". That is, if kernel at Computer 2 pid of
the process is 1500



On Mon, Mar 21, 2016 at 12:23 PM,  wrote:

> On Mon, 21 Mar 2016 10:33:44 +0530, Nitin Varyani said:
>
> > Sub-task 1: Until now, parent process cannot control the pid of the
> forked
> > child. A pid gets assigned as a sequential number by the kernel at the
> time
> > the process is forked . I want to modify kernel in such a way that parent
> > process can control the pid of the forked child.
>
> What does controlling the pid gain you?  To what purpose?
>
> > Sub-task 2: On Linux, you can find the maximum PID value for your system
> > with the following command:
> >
> > $ cat /proc/sys/kernel/pid_max
> >
> > Suppose pid_max=2000 for a system. I want that the parent process should
> be
> > able to assign a pid which is greater that 2000 to the forked child.
>
> Again, why would you want to do that?
>
> Anyhow...
>
> echo 3000 > /proc/sys/kernel/pid_max
> fork a process that gets a pid over 2000.
>
> Done.
>
> Note that on 32 bit systems, using a pid_max of over 32768 will cause
> various things in /proc to blow up.
>
> I suspect that you need to think harder about what problem you're actually
> trying to solve here - what will you do with a controlled child PID? Why
> does
> it even matter?
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Is it possible to turn off the gcc optimization when compiling kernel?

2016-03-21 Thread Nicholas Mc Guire
On Sun, Mar 20, 2016 at 02:46:41PM +0800, Hao Lee wrote:
> Hi,
> When I am debugging the linux kernel, I find that the execution
> sequence of some code is very strange. I think I need to turn off gcc
> optimization by  changing "-O2" to "-O0". But I encounter many errors.
> So, I want to know is it possible to turn off the gcc optimization or
> how can I compile some functions without optimization.

You can not turn it off in all functions as some need particluar 
optimization flags to comile at all, but you can pass 
individual CFLAGS per file via the Makefile

CFLAGS_target.o = -O0 or -flags-to-use

aswell as remove specific CFLAGS with

CFLAGS_REMOVE_target.o = -flags-to-remove

but if you want to debug the kernel it is most likely not
a good idea to try and disable optimization as the code you then
are debugging might not have that much to do with the final code
once optimization is on again. So simply generate the .lst file
of the target you are trying to debug e.g. for kernel/sched/core.c:

make kernel/sched/core.lst

and then use that .lst file to understand the output of gdb you
are inspecting.

thx!
hofrat

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


Re: Can interrupt be missed between interrupt disable/enable window?

2016-03-21 Thread Crazyiop
Hi,

When interrupt are globally disabled, interrupt are still detected and their 
flag set by their specific hardware circuit. It's only their immediat 
processing that are disabled. 

After reenabling interrupt, they will be treated right away, as their flag are 
still set. it would looks like the interrupt trigger Just happened. 

An interrupt miss is a problem if an interrupt is triggered a second time 
before the first one has been treated. That's When information is lost. 

This is impossible in some case and harmless in other. 

For the rest, the driver know something happens, but canot be sur of the number 
of triggers. As the interrupt are not lost, the driver's interrupt function is 
still called and has an opportunity to check it out, and act accordingly.

++


Le 21 mars 2016 08:11:54 GMT+01:00, Vishwas Srivastava  
a écrit :
>Kernel code heavily uses the spinlock primitives
>spin_lock_irqsave/restore plus local interrupt disabling/ enabling, all
>across the code.
>Is there a possibility that the interrupts might get
>missed in this small window
>
>disable interrupts
>.
>.<<<--
>interrupts is trigerred here
>
>enable interrupts
>
>
>specially when the irq
>affinity has been set to the same core on which the
>above mentioned code (disabling / enabling the irq's)
>runs?
>How the linux deals with this kind of scenario?
>
>
>
>
>___
>Kernelnewbies mailing list
>Kernelnewbies@kernelnewbies.org
>http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: add_disk() make my driver's initialisation, thus kernel stall.

2016-03-21 Thread 张云
Maybe I had misunderstood your meaning. 
You are meaning I have assign 0 to my device major number? 
The major variable is reassigned by the kernel in blkplay_init function.

http://stackoverflow.com/questions/13518404/add-disk-hangs-on-insmod 

This post solve the problem.

Now, I can compile it, insmod it. But it’s give me a permission error when I 
open the device.

> On Mar 21, 2016, at 10:55 AM, valdis.kletni...@vt.edu wrote:
> 
> On Mon, 21 Mar 2016 09:53:47 +0800, 张云 said:
>> The code is just for learning block driver
> 
> THe kernel doesn't know that.  You call a routine with the wrong
> parameters, it will not work properly.

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


Re: Can interrupt be missed between interrupt disable/enable window?

2016-03-21 Thread Chetan Nanda
On Mon, Mar 21, 2016 at 12:41 PM, Vishwas Srivastava
 wrote:
> Kernel code heavily uses the spinlock primitives
> spin_lock_irqsave/restore plus local interrupt disabling/ enabling, all
> across the code.
> Is there a possibility that the interrupts might get
> missed in this small window
>
> disable interrupts
> .
> .<<<--
> interrupts is trigerred here
>
> enable interrupts
>

As per my understanding, During disable period interrupt delivery to a
local core is disabled.
So, when interrupts are enabled (for that core) again then interrupt
will be delivered to that core .So no interrupt missed.

But if there are multiple interrupt from same source during the
disabled period then core will be interrupted once after interrupts
enabled again, i.e. all interrupt except one are missed by core,

Thanks,
Chetan Nanda

>
> specially when the irq
> affinity has been set to the same core on which the
> above mentioned code (disabling / enabling the irq's)
> runs?
> How the linux deals with this kind of scenario?
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

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


Can interrupt be missed between interrupt disable/enable window?

2016-03-21 Thread Vishwas Srivastava
Kernel code heavily uses the spinlock primitives
spin_lock_irqsave/restore plus local interrupt disabling/ enabling, all
across the code.
Is there a possibility that the interrupts might get
missed in this small window

disable interrupts
.
.<<<--
interrupts is trigerred here

enable interrupts


specially when the irq
affinity has been set to the same core on which the
above mentioned code (disabling / enabling the irq's)
runs?
How the linux deals with this kind of scenario?
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Attach my own pid

2016-03-21 Thread Valdis . Kletnieks
On Mon, 21 Mar 2016 10:33:44 +0530, Nitin Varyani said:

> Sub-task 1: Until now, parent process cannot control the pid of the forked
> child. A pid gets assigned as a sequential number by the kernel at the time
> the process is forked . I want to modify kernel in such a way that parent
> process can control the pid of the forked child.

What does controlling the pid gain you?  To what purpose?

> Sub-task 2: On Linux, you can find the maximum PID value for your system
> with the following command:
>
> $ cat /proc/sys/kernel/pid_max
>
> Suppose pid_max=2000 for a system. I want that the parent process should be
> able to assign a pid which is greater that 2000 to the forked child.

Again, why would you want to do that?

Anyhow...

echo 3000 > /proc/sys/kernel/pid_max
fork a process that gets a pid over 2000.

Done.

Note that on 32 bit systems, using a pid_max of over 32768 will cause
various things in /proc to blow up.

I suspect that you need to think harder about what problem you're actually
trying to solve here - what will you do with a controlled child PID? Why does
it even matter?


pgphQSdxEIsSG.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


kernel_thread() causes segfault

2016-03-21 Thread Shashank Khasare
Hi,

I want to write a new syscall in which caller process would create kernel
thread which shares the process address space, file descriptor table,
parent pid etc.
The new kernel thread would be clone of current thread but it would never
execute any userspace code.

The kernel_thread() function with following arguments would be ideal to
achieve this task:
kernel_thread(some_function, some_args, CLONE_FS | CLONE_FILES |
CLONE_PARENT)

In latest kernels (v3.1x), this function causes segmentation fault in the
user process.
However same code works perfectly in older kernels (v2.6).

According to this link
,
and this code

(call chain: kernel_thread -> do_fork -> copy_process -> copy_thread), it
looks like only the kernel thread can spawn another kernel thread. (I tried
to set PF_KTHREAD flag in current->flags before calling kernel_thread
function, but the system crashed.)

Is there any clean way of creating kernel thread that shares process
address space, file descriptor table, parent pid etc?


Thanks,
Shashank Khasare
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies