Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Thu, 22 Nov 2001 02:02:27 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Thu, 22 Nov 2001 02:02:20 -0500 Received: from posta2.elte.hu ([157.181.151.9]:27586 "HELO posta2.elte.hu") by vger.kernel.org with SMTP id ; Thu, 22 Nov 2001 02:02:06 -0500 Date: Thu, 22 Nov 2001 09:59:47 +0100 (CET) From: Ingo Molnar Reply-To: To: Cc: Subject: [patch] sched_[set|get]_affinity() syscall, 2.4.15-pre9 Message-ID: MIME-Version: 1.0 Content-Type: MULTIPART/Mixed; BOUNDARY="8323328-295900366-1006347495=:10030" Content-ID: Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. Send mail to mime@docserver.cac.washington.edu for more info. --8323328-295900366-1006347495=:10030 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII Content-ID: the attached set-affinity-A1 patch is relative to the scheduler fixes/cleanups in 2.4.15-pre9. It implements the following two new system calls: asmlinkage int sys_sched_set_affinity(pid_t pid, unsigned int mask_len, unsigned long *new_mask_ptr); asmlinkage int sys_sched_get_affinity(pid_t pid, unsigned int *user_mask_len_ptr, unsigned long *user_mask_ptr); as a testcase, softirq.c is updated to use this mechanizm, plus see the attached loop_affine.c code. the sched_set_affinity() syscall also ensures that the target process will run on the right CPU (or CPUs). I think this interface is the right way to expose user-selectable affinity to user-space - there are more complex affinity interfaces in existence, but i believe that the discovery of actual caching hierarchy is and should be up to a different mechanizm, i dont think it should be mixed into the affinity syscalls. Using a mask of linear CPU IDs is IMO sufficient to express user-space affinity wishes. There are no security issues wrt. cpus_allowed, so these syscalls are available to every process. (there are permission restrictions of course, similar to those of existing scheduler syscalls.) sched_get_affinity(pid, &mask_len, NULL) can be used to query the kernel's supported CPU bitmask length. This should help us in achieving a stable libc interface once we get over the 32/64 CPUs limit. the attached loop_affine.c code tests both syscalls: mars:~> ./loop_affine current process's affinity: 4 bytes mask, value 000000ff. trying to set process: affinity to 00000001. current process's affinity: 4 bytes mask, value 00000001. speed: 2162052 loops. speed: 2162078 loops. [...] i've tested the patch on both SMP and UP systems. On UP the syscalls are pretty pointless, but they show that the internal state of the scheduler folds nicely into the UP case as well: mars:~> ./loop_affine current process's affinity: 4 bytes mask, value 00000001. trying to set process: affinity to 00000001. current process's affinity: 4 bytes mask, value 00000001. speed: 2160880 loops. speed: 2160511 loops. [...] comments? Is there any reason to do a more complex interface than this? Ingo --8323328-295900366-1006347495=:10030 Content-Type: TEXT/PLAIN; charset=US-ASCII; name="set-affinity-2.4.15-A1" Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename="set-affinity-2.4.15-A1" LS0tIGxpbnV4L2tlcm5lbC9zY2hlZC5jLm9yaWcJV2VkIE5vdiAyMSAxMTox MjowNSAyMDAxDQorKysgbGludXgva2VybmVsL3NjaGVkLmMJV2VkIE5vdiAy MSAxMTo0NDo0MSAyMDAxDQpAQCAtMTExMiw2ICsxMTEyLDEzMiBAQA0KIAly ZXR1cm4gcmV0dmFsOw0KIH0NCiANCisvKg0KKyAqIHN5c19zY2hlZF9zZXRf YWZmaW5pdHkgLSBTZXQgdGhlIENQVSBhZmZpbml0eSBtYXNrLg0KKyAqDQor ICogQHBpZDogdGhlIFBJRCBvZiB0aGUgcHJvY2Vzcw0KKyAqIEBtYXNrX2xl bjogbGVuZ3RoIG9mIHRoZSBiaXRmaWVsZA0KKyAqIEBuZXdfbWFza19wdHI6 IHVzZXItc3BhY2UgcG9pbnRlciB0byB0aGUgbmV3IENQVSBtYXNrIGJpdGZp ZWxkDQorICovDQorYXNtbGlua2FnZSBpbnQgc3lzX3NjaGVkX3NldF9hZmZp bml0eShwaWRfdCBwaWQsIHVuc2lnbmVkIGludCBtYXNrX2xlbiwgdW5zaWdu ZWQgbG9uZyAqbmV3X21hc2tfcHRyKQ0KK3sNC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op_affine.c" Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename="loop_affine.c" DQovKg0KICogU2ltcGxlIGxvb3AgdGVzdGluZyB0aGUgQ1BVLWFmZmluaXR5 IHN5c2NhbGwuDQogKi8NCiNpbmNsdWRlIDx0aW1lLmg+DQojaW5jbHVkZSA8 c3RkaW8uaD4NCiNpbmNsdWRlIDxzdGRsaWIuaD4NCiNpbmNsdWRlIDxsaW51 eC91bmlzdGQuaD4NCg0KI2RlZmluZSBfX05SX3NjaGVkX3NldF9hZmZpbml0 eSAyMjYNCl9zeXNjYWxsMyAoaW50LCBzY2hlZF9zZXRfYWZmaW5pdHksIHBp ZF90LCBwaWQsIHVuc2lnbmVkIGludCwgbWFza19sZW4sIHVuc2lnbmVkIGxv bmcgKiwgbWFzaykNCg0KI2RlZmluZSBfX05SX3NjaGVkX2dldF9hZmZpbml0 eSAyMjcNCl9zeXNjYWxsMyAoaW50LCBzY2hlZF9nZXRfYWZmaW5pdHksIHBp ZF90LCBwaWQsIHVuc2lnbmVkIGludCAqLCBtYXNrX2xlbiwgdW5zaWduZWQg bG9uZyAqLCBtYXNrKQ0KDQppbnQgbWFpbiAodm9pZCkNCnsNCglpbnQgcmV0 Ow0KCXVuc2lnbmVkIGludCBub3csIGNvdW50LCBtYXNrX2xlbiwgaXRlcmF0 aW9uOw0KCXVuc2lnbmVkIGxvbmcgbWFzaywgbmV3X21hc2sgPSAoMSA8PCAw KTsNCg0KCXJldCA9IHNjaGVkX2dldF9hZmZpbml0eSgwLCAmbWFza19sZW4s ICZtYXNrKTsNCglpZiAocmV0KSB7DQoJCXByaW50Zigic2NoZWRfZ2V0X2Fm ZmluaXR5IHJldHVybmVkICVkLCBleGl0aW5nLlxuIiwgcmV0KTsNCgkJcmV0 dXJuIC0xOw0KCX0NCglwcmludGYoImN1cnJlbnQgcHJvY2VzcydzIGFmZmlu aXR5OiAlZCBieXRlcyBtYXNrLCB2YWx1ZSAlMDhseC5cbiIsDQoJCW1hc2tf bGVuLCBtYXNrKTsNCg0KCXByaW50ZigidHJ5aW5nIHRvIHNldCBwcm9jZXNz OiBhZmZpbml0eSB0byAlMDhseC5cbiIsIG5ld19tYXNrKTsJDQoNCglyZXQg PSBzY2hlZF9zZXRfYWZmaW5pdHkoMCwgc2l6ZW9mKG5ld19tYXNrKSwgJm5l d19tYXNrKTsNCglpZiAocmV0KSB7DQoJCXByaW50Zigic2NoZWRfc2V0X2Fm ZmluaXR5IHJldHVybmVkICVkLCBleGl0aW5nLlxuIiwgcmV0KTsNCgkJcmV0 dXJuIC0xOw0KCX0NCg0KCXJldCA9IHNjaGVkX2dldF9hZmZpbml0eSgwLCAm bWFza19sZW4sICZtYXNrKTsNCglpZiAocmV0KSB7DQoJCXByaW50Zigic2No ZWRfZ2V0X2FmZmluaXR5IHJldHVybmVkICVkLCBleGl0aW5nLlxuIiwgcmV0 KTsNCgkJcmV0dXJuIC0xOw0KCX0NCglwcmludGYoImN1cnJlbnQgcHJvY2Vz cydzIGFmZmluaXR5OiAlZCBieXRlcyBtYXNrLCB2YWx1ZSAlMDhseC5cbiIs DQoJCW1hc2tfbGVuLCBtYXNrKTsNCglpdGVyYXRpb24gPSAwOw0KcmVwZWF0 Og0KCW5vdyA9IHRpbWUoMCk7DQoJY291bnQgPSAwOw0KCWZvciAoOzspIHsN CgkJY291bnQrKzsNCgkJaWYgKHRpbWUoMCkgIT0gbm93KQ0KCQkJYnJlYWs7 DQoJfQ0KCWlmIChpdGVyYXRpb24pDQoJCXByaW50Zigic3BlZWQ6ICVkIGxv b3BzLlxuIiwgY291bnQpOw0KCWl0ZXJhdGlvbisrOw0KCWdvdG8gcmVwZWF0 Ow0KCXJldHVybiAwOw0KfQ0K --8323328-295900366-1006347495=:10030-- - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/