Re: Real time application programming - sched_setattr() fails if I set CPU affinity using sched_setaffinity().

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have used that call/macro, CPU_SET, prior to calling
sched_setaffinity(), I missed mentioning that in earlier post.. sorry
for that.
My machine is Intel(R) Core(TM)2 Duo CPU , which shows to processors 0 and 1.

    struct sched_attr attr;
    cpu_set_t set;
    CPU_ZERO(&set);
    CPU_SET(0, &set);             // It doesnt make a difference in
output even I modify this to CPU_SET(1,&set)
    unsigned int flags=0;

          if(sched_setaffinity(0,sizeof(set), &set) < 0)
          {
                          //printf("\nmask= %ld\n",mask);
                          perror("sched_setaffinity :");
                          return 0;
          }

Note:
Based on your reply, I tried setting CPU1 or CPU0 individually and
also 2 cpu sets but to no use. To enable both CPUs (As I am not sure
how to get current CPU mask, so tried all combinations, my PC is just
dual core), tried this code, (AND of both sets one containing CPU0 and
another CPU1) but sched_setaffinity() is failing with this:

    cpu_set_t set1,set2,set3;
    CPU_ZERO(&set1);
    CPU_ZERO(&set2);
    CPU_SET(0, &set1);
    CPU_SET(1, &set2);
    CPU_AND_S(sizeof(set1),&set3,&set1,&set2);    //set3 is the
destination cpu set
    unsigned int flags=0;

          if(sched_setaffinity(0,sizeof(set3), &set3) < 0)
          {
                          //printf("\nmask= %ld\n",mask);
                          perror("sched_setaffinity :");
                          return 0;
          }

On Mon, Nov 20, 2017 at 12:48 PM, Juri Lelli <juri.lelli@xxxxxxxxx> wrote:
> Hi Bhargav,
>
> On 20/11/17 10:09, bhargavb wrote:
>> Hello,
>>
>> Working on a real time application, Getting runtime error at
>> sched_setattr as "Operation Not permitted".Running on Ubuntu 16.04 LTS
>> (4.4.0-97-generic kernel, x86_64 platform)
>> C program code excerpt as below:
>>
>> unsigned int flags = 0;
>> sched_getattr(0, &attr, sizeof (struct sched_attr), 0);
>> if (ret != 0)
>> perror("getattr failed:");
>> attr.sched_policy = SCHED_DEADLINE;
>> attr.sched_runtime = 5 * 100 * 1000;
>> attr.sched_deadline = 8 * 100 * 1000;
>> attr.sched_period = 10 * 100 * 1000;
>> attr.size = sizeof (attr);
>> attr.sched_flags = 0;
>> attr.sched_nice = 0;
>> attr.sched_priority = 0;
>>
>> if(sched_setaffinity(0,sizeof(set), &set) < 0)
>> {
>> perror("sched_setaffinity :");
>> return 0;
>> }
>> ret = sched_setattr(0, &attr, flags);
>> if(ret!=0)
>> {
>> perror("sched_setattr failed: ");
>> }
>>
>> But, If I comment the sched_setaffinity() call, it runs without error.
>> Also, using SCHED_FIFO by calling sched_setscheduler() doesn't give me
>> any error after setting CPU affinity. Only the combination of
>> sched_setaffinity with sched_setattr() generates error. I am running
>> in sudo mode.
>
> Problem is that SCHED_DEADLINE tasks can't have an affinity mask smaller than
> the root domain they are on [1]. You've got to use cpuset to achieve what you
> want.
>
> Best,
>
> Juri
>
> [1] https://elixir.free-electrons.com/linux/latest/source/Documentation/scheduler/sched-deadline.txt#L620



-- 
Bhargav
--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux