示例#1
0
/*
 *  ======== Algorithm_create ========
 */
Algorithm_Handle Algorithm_create(IALG_Fxns *fxns, Void *idma3FxnsVoid,
        Void *iresFxnsVoid, IALG_Params *params, Algorithm_Attrs *attrs)
{
    Algorithm_Obj *pObject = NULL;
    IDMA3_Fxns *idma3Fxns = (IDMA3_Fxns *)idma3FxnsVoid;
    IRES_Fxns  *iresFxns = (IRES_Fxns *)iresFxnsVoid;
    IRES_Status iresStatus;

    Log_print5(Diags_ENTRY, "[+E] Algorithm_create> Enter("
            "fxns=0x%x, idma3Fxns=0x%x, iresFxns=0x%x, params=0x%x, "
            "attrs=0x%x)",
            (IArg)fxns, (IArg)idma3Fxns, (IArg)iresFxns, (IArg)params,
            (IArg)attrs);

    assert(attrs != NULL);

    pObject = Memory_alloc(sizeof(Algorithm_Obj), NULL);
    if (pObject == NULL) {
        Log_print0(Diags_USER7, "[+7] Algorithm_create> "
                "Alloc for a small object FAILED -- out of memory?");
        goto Algorithm_create_return;
    }

    /*
     * Note that we don't have to validate groupId as that's done at
     * config time.
     */
    pObject->idma3Fxns = NULL;
    pObject->iresFxns = NULL;
    pObject->groupId = attrs->groupId;

    /* Call appropriate DSKT2 function, depending on attrs->useExtHeap */
    if (attrs->useExtHeap == FALSE) {
        /*
         *  Create alg normally, attempting to allocate algorithm memory
         *  in the requested memory spaces.
         */
        pObject->alg = DSKT2_createAlg(attrs->groupId, fxns, NULL, params);
    }
    else {
        /*
         *  Create alg with all algorithm memory allocated in external memory.
         */
        pObject->alg = DSKT2_createAlgExt(attrs->groupId, fxns, NULL, params);
    }

    if (pObject->alg == NULL) {
        Log_print0(Diags_USER7, "[+7] Algorithm_create> "
                "Algorithm creation FAILED; make sure that 1) alg params are "
                "correct/appropriate, 2) there is enough internal and external "
                "algorithm memory available -- check DSKT2 settings for heap "
                "assignments and scratch allocation");
        Algorithm_delete(pObject);
        pObject = NULL;
        goto Algorithm_create_return;
    }

    /* If alg implements IRES, allocate resources */
    if (iresFxns != NULL) {
        iresStatus = RMAN_assignResources(pObject->alg, iresFxns,
                pObject->groupId);

        if (iresStatus != IRES_OK) {
            Log_print1(Diags_USER7, "[+7] Algorithm_create> Assignment of "
                    "alg resources through RMAN FAILED (0x%x)",
                    (IArg)iresStatus);

            Algorithm_delete(pObject);
            pObject = NULL;
            goto Algorithm_create_return;
        }
        pObject->iresFxns = iresFxns;
    }

Algorithm_create_return:

    Log_print1(Diags_EXIT, "[+X] Algorithm_create> return (0x%x)",
            (IArg)pObject);

    return (pObject);
}
/*
 *  ======== Algorithm_create ========
 */
Algorithm_Handle Algorithm_create(IALG_Fxns *fxns, Void *idma3FxnsVoid,
        Void *iresFxnsVoid, IALG_Params *params, Algorithm_Attrs *attrs)
{
    Algorithm_Obj *pObject = NULL;
    Int         groupId;
    IDMA3_Fxns *idma3Fxns = (IDMA3_Fxns *)idma3FxnsVoid;
    IRES_Fxns  *iresFxns = (IRES_Fxns *)iresFxnsVoid;
    IRES_Status iresStatus;
    UInt32      useCachedMem;

    Log_print5(Diags_ENTRY, "[+E] Algorithm_create> Enter("
            "fxns=0x%x, idma3Fxns=0x%x, iresFxns=0x%x, params=0x%x, "
            "attrs=0x%x)",
            (IArg)fxns, (IArg)idma3Fxns, (IArg)iresFxns, (IArg)params,
            (IArg)attrs);

    groupId = (attrs != NULL) ? attrs->groupId : -1;
    useCachedMem = (attrs != NULL) ? attrs->useCachedMem :
            Algorithm_USECACHEDMEM_DEFAULT;

    Log_print1(Diags_USER2, "Algorithm_create> useCachedMem = %d",
            (IArg)useCachedMem);

    /* if (attrs == NULL) use default groupId */
    if ((pObject = (Algorithm_Obj *)Memory_alloc(sizeof(Algorithm_Obj),
                 NULL)) == NULL) {
        Log_print0(Diags_USER7, "[+7] Algorithm_create> "
                "Alloc for a small object FAILED -- out of memory?");
        goto Algorithm_create_return;
    }

    pObject->alg = ALG_create(groupId, fxns, NULL, params, useCachedMem);
    pObject->idma3Fxns = NULL;
    pObject->iresFxns = NULL;
    pObject->groupId = groupId;

    if (pObject->alg == NULL) {
        Log_print0(Diags_USER7, "[+7] Algorithm_create> "
                "Algorithm creation FAILED; make sure that 1) alg params are "
                "correct/appropriate, 2) there is enough internal and external "
                "algorithm memory available -- check DSKT2 settings for heap "
                "assignments and scratch allocation");
        Algorithm_delete(pObject);
        pObject = NULL;
        goto Algorithm_create_return;
    }

    /* if the alg implements IDMA3, we need to negotiate DMA resources */
    if (idma3Fxns != NULL) {
        Int status;
        status = DMAN3_grantDmaChannels(pObject->groupId, &pObject->alg,
                &idma3Fxns, 1);

        if (status != DMAN3_SOK) {
            Log_print1(Diags_USER7, "[+7] Algorithm_create> "
                    "Granting DMA channels to algorithm through DMAN3 FAILED"
                    " (0x%x)", (IArg)status);
            Algorithm_delete(pObject);
            pObject = NULL;
            goto Algorithm_create_return;
        }

        pObject->idma3Fxns = idma3Fxns;  /* tell Algorithm_delete to release */
    }

    /* If alg implements IRES, allocate resources */
    if (iresFxns != NULL) {
        iresStatus = RMAN_assignResources(pObject->alg, iresFxns,
                pObject->groupId);

        if (iresStatus != IRES_OK) {
            Log_print1(Diags_USER7, "[+7] Algorithm_create> Assignment of "
                    "alg resources through RMAN FAILED (0x%x)",
                    (IArg)iresStatus);

            /* Free DMAN3 channels, if allocated */
            if (idma3Fxns != NULL) {
                DMAN3_releaseDmaChannels(&(pObject->alg),
                        &(pObject->idma3Fxns), 1);
            }

            Algorithm_delete(pObject);
            pObject = NULL;
            goto Algorithm_create_return;
        }
        pObject->iresFxns = iresFxns;
    }

Algorithm_create_return:

    Log_print1(Diags_EXIT, "[+X] Algorithm_create> return (0x%x)",
            (IArg)pObject);

    return (pObject);
}