get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/260/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 260,
    "url": "http://patchwork.ozlabs.org/api/patches/260/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/cbe-oss-dev/patch/200809120922.02342.adetsch@br.ibm.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.ozlabs.org/api/projects/1/?format=api",
        "name": "Cell Broadband Engine development",
        "link_name": "cbe-oss-dev",
        "list_id": "cbe-oss-dev.ozlabs.org",
        "list_email": "cbe-oss-dev@ozlabs.org",
        "web_url": null,
        "scm_url": null,
        "webscm_url": null,
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<200809120922.02342.adetsch@br.ibm.com>",
    "list_archive_url": null,
    "date": "2008-09-12T12:22:02",
    "name": "powerpc/spufs: Implement SPU affinity on top of gang scheduling",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "b8e27717549894ece0a7000fd76eaf468dd8b42f",
    "submitter": {
        "id": 93,
        "url": "http://patchwork.ozlabs.org/api/people/93/?format=api",
        "name": "Andre Detsch",
        "email": "adetsch@br.ibm.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patchwork.ozlabs.org/api/users/1/?format=api",
        "username": "jk",
        "first_name": "Jeremy",
        "last_name": "Kerr",
        "email": "jk@ozlabs.org"
    },
    "mbox": "http://patchwork.ozlabs.org/project/cbe-oss-dev/patch/200809120922.02342.adetsch@br.ibm.com/mbox/",
    "series": [],
    "comments": "http://patchwork.ozlabs.org/api/patches/260/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/260/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<cbe-oss-dev-bounces+patchwork=ozlabs.org@ozlabs.org>",
        "X-Original-To": [
            "patchwork@ozlabs.org",
            "cbe-oss-dev@ozlabs.org"
        ],
        "Delivered-To": [
            "patchwork@ozlabs.org",
            "cbe-oss-dev@ozlabs.org"
        ],
        "Received": [
            "from ozlabs.org (localhost [127.0.0.1])\n\tby ozlabs.org (Postfix) with ESMTP id E20AEDE111\n\tfor <patchwork@ozlabs.org>; Fri, 12 Sep 2008 22:23:21 +1000 (EST)",
            "from igw2.br.ibm.com (igw2.br.ibm.com [32.104.18.25])\n\t(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\n\t(Client CN \"mailgw2.br.ibm.com\", Issuer \"Equifax\" (not verified))\n\tby ozlabs.org (Postfix) with ESMTPS id 284EDDDEFA;\n\tFri, 12 Sep 2008 22:23:13 +1000 (EST)",
            "from mailhub3.br.ibm.com (mailhub3 [9.18.232.110])\n\tby igw2.br.ibm.com (Postfix) with ESMTP id 691C817F5B8;\n\tFri, 12 Sep 2008 09:07:55 -0300 (BRT)",
            "from d24av01.br.ibm.com (d24av01.br.ibm.com [9.18.232.46])\n\tby mailhub3.br.ibm.com (8.13.8/8.13.8/NCO v8.7) with ESMTP id\n\tm8CCMogE3657884; Fri, 12 Sep 2008 09:22:50 -0300",
            "from d24av01.br.ibm.com (loopback [127.0.0.1])\n\tby d24av01.br.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id\n\tm8CCMhBV011910; Fri, 12 Sep 2008 09:22:43 -0300",
            "from [9.8.2.195] ([9.8.2.195])\n\tby d24av01.br.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id\n\tm8CCMhfL011895; Fri, 12 Sep 2008 09:22:43 -0300"
        ],
        "From": "Andre Detsch <adetsch@br.ibm.com>",
        "To": "cbe-oss-dev@ozlabs.org",
        "Date": "Fri, 12 Sep 2008 09:22:02 -0300",
        "User-Agent": "KMail/1.9.6",
        "References": "<200809111955.28780.adetsch@br.ibm.com>\n\t<200809112038.27534.adetsch@br.ibm.com>\n\t<200809120918.48519.adetsch@br.ibm.com>",
        "In-Reply-To": "<200809120918.48519.adetsch@br.ibm.com>",
        "MIME-Version": "1.0",
        "Content-Disposition": "inline",
        "Message-Id": "<200809120922.02342.adetsch@br.ibm.com>",
        "Cc": "LukeBrowning@us.ibm.com, Jeremy Kerr <jk@ozlabs.org>",
        "Subject": "[Cbe-oss-dev] [PATCH 11/11 v2] powerpc/spufs: Implement SPU\n\taffinity on top of gang scheduling",
        "X-BeenThere": "cbe-oss-dev@ozlabs.org",
        "X-Mailman-Version": "2.1.11",
        "Precedence": "list",
        "List-Id": "Discussion about Open Source Software for the Cell Broadband Engine\n\t<cbe-oss-dev.ozlabs.org>",
        "List-Unsubscribe": "<https://ozlabs.org/mailman/options/cbe-oss-dev>,\n\t<mailto:cbe-oss-dev-request@ozlabs.org?subject=unsubscribe>",
        "List-Archive": "<http://ozlabs.org/pipermail/cbe-oss-dev>",
        "List-Post": "<mailto:cbe-oss-dev@ozlabs.org>",
        "List-Help": "<mailto:cbe-oss-dev-request@ozlabs.org?subject=help>",
        "List-Subscribe": "<https://ozlabs.org/mailman/listinfo/cbe-oss-dev>,\n\t<mailto:cbe-oss-dev-request@ozlabs.org?subject=subscribe>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Sender": "cbe-oss-dev-bounces+patchwork=ozlabs.org@ozlabs.org",
        "Errors-To": "cbe-oss-dev-bounces+patchwork=ozlabs.org@ozlabs.org"
    },
    "content": "SPU affinity, originally implemented before we had gang\nscheduling, was disabled after gang scheduling was\nintroduced.\n\nThis patch re-enables SPU affinity, making it fit the new scheduling\nalgorithm.\n\nSigned-off-by: Andre Detsch <adetsch@br.ibm.com>",
    "diff": "diff --git a/arch/powerpc/platforms/cell/spufs/sched.c \nb/arch/powerpc/platforms/cell/spufs/sched.c\nindex 8326034..d4ef6e3 100644\n--- a/arch/powerpc/platforms/cell/spufs/sched.c\n+++ b/arch/powerpc/platforms/cell/spufs/sched.c\n@@ -348,126 +348,97 @@ static void aff_set_offsets(struct spu_gang *gang)\n \tgang->aff_flags |= AFF_OFFSETS_SET;\n }\n \n-static struct spu *aff_ref_location(struct spu_context *ctx, int mem_aff,\n-\t\t int group_size, int lowest_offset)\n+static struct spu *ctx_location(struct spu *ref, int offset,\n+\t\t\t\tstruct spu_gang *gang)\n+{\n+\tstruct spu *spu;\n+\n+\tspu = NULL;\n+\tif (offset >= 0) {\n+\t\tlist_for_each_entry(spu, ref->aff_list.prev, aff_list) {\n+\t\t\tif ((!gang && spu->alloc_state == SPU_FREE) ||\n+\t\t\t\t\t\t\tspu->gang == gang) {\n+\t\t\t\tif (offset == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\toffset--;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tlist_for_each_entry_reverse(spu, ref->aff_list.next,\n+\t\t\t\t\t    aff_list) {\n+\t\t\tif ((!gang && spu->alloc_state == SPU_FREE) ||\n+\t\t\t\t\t\t\tspu->gang == gang) {\n+\t\t\t\tif (offset == 0)\n+\t\t\t\t\tbreak;\n+\t\t\t\toffset++;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\treturn spu;\n+}\n+\n+static int aff_place_gang(struct spu_gang *gang)\n {\n \tstruct spu *spu;\n \tint node, n;\n+\tstruct spu_context *ctx;\n+\tint mem_aff;\n+\n+\n+\tBUG_ON(list_empty(&gang->aff_list_head));\n+\n+\tif (!(gang->aff_flags & AFF_MERGED))\n+\t\taff_merge_remaining_ctxs(gang);\n+\tif (!(gang->aff_flags & AFF_OFFSETS_SET))\n+\t\taff_set_offsets(gang);\n+\n+\tmem_aff = gang->aff_ref_ctx->flags & SPU_CREATE_AFFINITY_MEM;\n \n-\t/*\n-\t * TODO: A better algorithm could be used to find a good spu to be\n-\t *       used as reference location for the ctxs chain.\n-\t */\n \tnode = cpu_to_node(raw_smp_processor_id());\n \tfor (n = 0; n < MAX_NUMNODES; n++, node++) {\n \t\tint available_spus;\n \n \t\tnode = (node < MAX_NUMNODES) ? node : 0;\n-\t\tif (!node_allowed(ctx->gang, node))\n+\t\tif (!node_allowed(gang, node))\n \t\t\tcontinue;\n \n \t\tavailable_spus = 0;\n \t\tspin_lock(&cbe_spu_info[node].list_lock);\n \t\tlist_for_each_entry(spu, &cbe_spu_info[node].spus, cbe_list) {\n-\t\t\tif (spu->ctx && spu->ctx->gang\n-\t\t\t\t\t&& spu->ctx->aff_offset == 0)\n-\t\t\t\tavailable_spus -=\n-\t\t\t\t\t(spu->ctx->gang->contexts - 1);\n-\t\t\telse\n+\t\t\tif (spu->alloc_state == SPU_FREE)\n \t\t\t\tavailable_spus++;\n \t\t}\n-\t\tif (available_spus < ctx->gang->contexts) {\n+\t\tif (available_spus < gang->contexts) {\n \t\t\tspin_unlock(&cbe_spu_info[node].list_lock);\n \t\t\tcontinue;\n \t\t}\n \n \t\tlist_for_each_entry(spu, &cbe_spu_info[node].spus, cbe_list) {\n \t\t\tif ((!mem_aff || spu->has_mem_affinity) &&\n-\t\t\t\t\t\t\tsched_spu(spu)) {\n+\t\t\t\t\t\tspu->alloc_state == SPU_FREE) {\n+\t\t\t\tgang->aff_ref_spu = spu;\n \t\t\t\tspin_unlock(&cbe_spu_info[node].list_lock);\n-\t\t\t\treturn spu;\n \t\t\t}\n \t\t}\n-\t\tspin_unlock(&cbe_spu_info[node].list_lock);\n-\t}\n-\treturn NULL;\n-}\n \n-static void aff_set_ref_point_location(struct spu_gang *gang)\n-{\n-\tint mem_aff, gs, lowest_offset;\n-\tstruct spu_context *ctx;\n-\tstruct spu *tmp;\n-\n-\tmem_aff = gang->aff_ref_ctx->flags & SPU_CREATE_AFFINITY_MEM;\n-\tlowest_offset = 0;\n-\tgs = 0;\n-\n-\tlist_for_each_entry(tmp, &gang->aff_list_head, aff_list)\n-\t\tgs++;\n+\t\tlist_for_each_entry(ctx, &gang->list, gang_list) {\n+\t\t\tspu = ctx_location(gang->aff_ref_spu, ctx->aff_offset,\n+\t\t\t\t\t   NULL);\n+\t\t\tBUG_ON(!spu);\n+\t\t\tspu->gang = gang;\n+\t\t}\n \n-\tlist_for_each_entry_reverse(ctx, &gang->aff_ref_ctx->aff_list,\n-\t\t\t\t\t\t\t\taff_list) {\n-\t\tif (&ctx->aff_list == &gang->aff_list_head)\n-\t\t\tbreak;\n-\t\tlowest_offset = ctx->aff_offset;\n+\t\tspin_unlock(&cbe_spu_info[node].list_lock);\n+\t\treturn 1;\n \t}\n-\n-\tgang->aff_ref_spu = aff_ref_location(gang->aff_ref_ctx, mem_aff, gs,\n-\t\t\t\t\t\t\tlowest_offset);\n+\treturn 0;\n }\n \n-static struct spu *ctx_location(struct spu *ref, int offset, int node)\n-{\n-\tstruct spu *spu;\n-\n-\tspu = NULL;\n-\tif (offset >= 0) {\n-\t\tlist_for_each_entry(spu, ref->aff_list.prev, aff_list) {\n-\t\t\tBUG_ON(spu->node != node);\n-\t\t\tif (offset == 0)\n-\t\t\t\tbreak;\n-\t\t\tif (sched_spu(spu))\n-\t\t\t\toffset--;\n-\t\t}\n-\t} else {\n-\t\tlist_for_each_entry_reverse(spu, ref->aff_list.next, aff_list) {\n-\t\t\tBUG_ON(spu->node != node);\n-\t\t\tif (offset == 0)\n-\t\t\t\tbreak;\n-\t\t\tif (sched_spu(spu))\n-\t\t\t\toffset++;\n-\t\t}\n-\t}\n-\n-\treturn spu;\n-}\n \n-/*\n- * affinity_check is called each time a context is going to be scheduled.\n- * It returns the spu ptr on which the context must run.\n- */\n static int has_affinity(struct spu_gang *gang)\n {\n-\tif (list_empty(&gang->aff_list_head))\n-\t\treturn 0;\n-\n-\t/*\n-\t * TODO: fix SPU Affinity to work with gang scheduling.\n-\t */\n-\n-\tif (atomic_read(&gang->aff_sched_count) == 0)\n-\t\tgang->aff_ref_spu = NULL;\n-\n-\tif (!gang->aff_ref_spu) {\n-\t\tif (!(gang->aff_flags & AFF_MERGED))\n-\t\t\taff_merge_remaining_ctxs(gang);\n-\t\tif (!(gang->aff_flags & AFF_OFFSETS_SET))\n-\t\t\taff_set_offsets(gang);\n-\t\taff_set_ref_point_location(gang);\n-\t}\n-\n-\treturn gang->aff_ref_spu != NULL;\n+\treturn !list_empty(&gang->aff_list_head);\n }\n \n /**\n@@ -486,9 +457,6 @@ static void spu_unbind_context(struct spu *spu, struct \nspu_context *ctx)\n  \tif (spu->ctx->flags & SPU_CREATE_NOSCHED)\n \t\tatomic_dec(&cbe_spu_info[spu->node].reserved_spus);\n \n-\tif (ctx->gang)\n-\t\tatomic_dec_if_positive(&ctx->gang->aff_sched_count);\n-\n \tspu_switch_notify(spu, NULL);\n \tspu_unmap_mappings(ctx);\n \tspu_save(&ctx->csa, spu);\n@@ -582,6 +550,21 @@ static struct spu *spu_bind(struct spu_gang *gang,\n \t\tif (!node_allowed(gang, node))\n \t\t\tcontinue;\n \n+\t\tif (has_affinity(gang)) {\n+\t\t\tspin_lock(&cbe_spu_info[node].list_lock);\n+\t\t\tspu = ctx_location(gang->aff_ref_spu, ctx->aff_offset,\n+\t\t\t\t\t   gang);\n+\t\t\tif (spu && (spu->alloc_state == SPU_FREE) &&\n+\t\t\t    (spu->gang == gang)) {\n+\t\t\t\tgoto found;\n+\t\t\t}\n+\n+\t\t\t/* If ctx_location returns an spu, it should be valid */\n+\t\t\tWARN_ON(spu);\n+\n+\t\t\tspin_unlock(&cbe_spu_info[node].list_lock);\n+\t\t}\n+\n \t\tspin_lock(&cbe_spu_info[node].list_lock);\n \t\tlist_for_each_entry(spu, &cbe_spu_info[node].spus, cbe_list) {\n \t\t\tif ((spu->alloc_state == SPU_FREE) &&\n@@ -646,6 +629,7 @@ static void spu_unschedule(struct spu_gang *gang)\n \t\tspin_unlock(&cbe_spu_info[node].list_lock);\n \t\tmutex_unlock(&ctx->state_mutex);\n \t}\n+\tgang->aff_ref_spu = NULL;\n }\n \n static int spu_get_idle(struct spu_gang *gang, int node)\n@@ -656,7 +640,9 @@ static int spu_get_idle(struct spu_gang *gang, int node)\n \n \tspu_context_nospu_trace(spu_get_idle__enter, gang);\n \n-\t/* TO DO: SPU affinity scheduling. */\n+\tif (has_affinity(gang) && !gang->aff_ref_spu)\n+\t\tret = aff_place_gang(gang);\n+\t\tgoto spu_get_idle_out;\n \n \tmode = SPU_RESERVE;\n \n@@ -676,6 +662,7 @@ spu_get_idle_top:\n \t\t\tcontinue;\n \n \t\tspin_lock(&cbe_spu_info[lnode].list_lock);\n+\n \t\tlist_for_each_entry(spu, &cbe_spu_info[lnode].spus, cbe_list) {\n \t\t\tswitch (mode) {\n \t\t\tcase SPU_RESERVE :\ndiff --git a/arch/powerpc/platforms/cell/spufs/spufs.h \nb/arch/powerpc/platforms/cell/spufs/spufs.h\nindex 6afc514..907baf9 100644\n--- a/arch/powerpc/platforms/cell/spufs/spufs.h\n+++ b/arch/powerpc/platforms/cell/spufs/spufs.h\n@@ -178,7 +178,6 @@ struct spu_gang {\n \tstruct mutex aff_mutex;\n \tint aff_flags;\n \tstruct spu *aff_ref_spu;\n-\tatomic_t aff_sched_count;\n \n \t/* spu scheduler statistics for zombie ctxts */\n \tstruct {\n",
    "prefixes": []
}