Changeset 8565a42 in mainline for kernel/generic/src/mm/frame.c


Ignore:
Timestamp:
2018-03-02T20:34:50Z (7 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a1a81f69, d5e5fd1
Parents:
3061bc1 (diff), 34e1206 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:34:50)
git-committer:
GitHub <noreply@…> (2018-03-02 20:34:50)
Message:

Remove all trailing whitespace, everywhere.

See individual commit messages for details.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/frame.c

    r3061bc1 r8565a42  
    108108                return (size_t) -1;
    109109        }
    110        
     110
    111111        size_t i;
    112112        for (i = 0; i < zones.count; i++) {
     
    114114                if (overlaps(zones.info[i].base, zones.info[i].count,
    115115                    base, count)) {
    116                        
     116
    117117                        /*
    118118                         * If the overlaping zones are of the same type
     
    121121                         *
    122122                         */
    123                        
     123
    124124                        if ((zones.info[i].flags != flags) ||
    125125                            (!iswithin(zones.info[i].base, zones.info[i].count,
     
    132132                                    (void *) PFN2ADDR(zones.info[i].count));
    133133                        }
    134                        
     134
    135135                        return (size_t) -1;
    136136                }
     
    138138                        break;
    139139        }
    140        
     140
    141141        /* Move other zones up */
    142142        for (size_t j = zones.count; j > i; j--)
    143143                zones.info[j] = zones.info[j - 1];
    144        
     144
    145145        zones.count++;
    146        
     146
    147147        return i;
    148148}
     
    163163        for (i = 0; i < zones.count; i++)
    164164                total += zones.info[i].free_count;
    165        
     165
    166166        return total;
    167167}
     
    195195        if (hint >= zones.count)
    196196                hint = 0;
    197        
     197
    198198        size_t i = hint;
    199199        do {
     
    201201                    && (zones.info[i].base + zones.info[i].count >= frame + count))
    202202                        return i;
    203                
     203
    204204                i++;
    205205                if (i >= zones.count)
    206206                        i = 0;
    207                
     207
    208208        } while (i != hint);
    209        
     209
    210210        return (size_t) -1;
    211211}
     
    219219         * the bitmap if the last argument is NULL.
    220220         */
    221        
     221
    222222        return ((zone->flags & ZONE_AVAILABLE) &&
    223223            bitmap_allocate_range(&zone->bitmap, count, zone->base,
     
    245245        for (size_t pos = 0; pos < zones.count; pos++) {
    246246                size_t i = (pos + hint) % zones.count;
    247                
     247
    248248                /* Check whether the zone meets the search criteria. */
    249249                if (!ZONE_FLAGS_MATCH(zones.info[i].flags, flags))
    250250                        continue;
    251                
     251
    252252                /* Check if the zone can satisfy the allocation request. */
    253253                if (zone_can_alloc(&zones.info[i], count, constraint))
    254254                        return i;
    255255        }
    256        
     256
    257257        return (size_t) -1;
    258258}
     
    291291        for (size_t pos = 0; pos < zones.count; pos++) {
    292292                size_t i = (pos + hint) % zones.count;
    293                
     293
    294294                /* Skip zones containing only high-priority memory. */
    295295                if (is_high_priority(zones.info[i].base, zones.info[i].count))
    296296                        continue;
    297                
     297
    298298                /* Check whether the zone meets the search criteria. */
    299299                if (!ZONE_FLAGS_MATCH(zones.info[i].flags, flags))
    300300                        continue;
    301                
     301
    302302                /* Check if the zone can satisfy the allocation request. */
    303303                if (zone_can_alloc(&zones.info[i], count, constraint))
    304304                        return i;
    305305        }
    306        
     306
    307307        return (size_t) -1;
    308308}
     
    328328        if (hint >= zones.count)
    329329                hint = 0;
    330        
     330
    331331        /*
    332332         * Prefer zones with low-priority memory over
    333333         * zones with high-priority memory.
    334334         */
    335        
     335
    336336        size_t znum = find_free_zone_lowprio(count, flags, constraint, hint);
    337337        if (znum != (size_t) -1)
    338338                return znum;
    339        
     339
    340340        /* Take all zones into account */
    341341        return find_free_zone_all(count, flags, constraint, hint);
     
    350350{
    351351        assert(index < zone->count);
    352        
     352
    353353        return &zone->frames[index];
    354354}
     
    371371{
    372372        assert(zone->flags & ZONE_AVAILABLE);
    373        
     373
    374374        /* Allocate frames from zone */
    375375        size_t index = (size_t) -1;
    376376        int avail = bitmap_allocate_range(&zone->bitmap, count, zone->base,
    377377            FRAME_LOWPRIO, constraint, &index);
    378        
     378
    379379        assert(avail);
    380380        assert(index != (size_t) -1);
    381        
     381
    382382        /* Update frame reference count */
    383383        for (size_t i = 0; i < count; i++) {
    384384                frame_t *frame = zone_get_frame(zone, index + i);
    385                
     385
    386386                assert(frame->refcount == 0);
    387387                frame->refcount = 1;
    388388        }
    389        
     389
    390390        /* Update zone information. */
    391391        zone->free_count -= count;
    392392        zone->busy_count += count;
    393        
     393
    394394        return index;
    395395}
     
    408408{
    409409        assert(zone->flags & ZONE_AVAILABLE);
    410        
     410
    411411        frame_t *frame = zone_get_frame(zone, index);
    412        
     412
    413413        assert(frame->refcount > 0);
    414        
     414
    415415        if (!--frame->refcount) {
    416416                bitmap_set(&zone->bitmap, index, 0);
    417                
     417
    418418                /* Update zone information. */
    419419                zone->free_count++;
    420420                zone->busy_count--;
    421                
     421
    422422                return 1;
    423423        }
    424        
     424
    425425        return 0;
    426426}
     
    430430{
    431431        assert(zone->flags & ZONE_AVAILABLE);
    432        
     432
    433433        frame_t *frame = zone_get_frame(zone, index);
    434434        if (frame->refcount > 0)
    435435                return;
    436        
     436
    437437        frame->refcount = 1;
    438438        bitmap_set_range(&zone->bitmap, index, 1);
    439        
     439
    440440        zone->free_count--;
    441441        reserve_force_alloc(1);
     
    462462        assert(!overlaps(zones.info[z1].base, zones.info[z1].count,
    463463            zones.info[z2].base, zones.info[z2].count));
    464        
     464
    465465        /* Difference between zone bases */
    466466        pfn_t base_diff = zones.info[z2].base - zones.info[z1].base;
    467        
     467
    468468        zones.info[z1].count = base_diff + zones.info[z2].count;
    469469        zones.info[z1].free_count += zones.info[z2].free_count;
    470470        zones.info[z1].busy_count += zones.info[z2].busy_count;
    471        
     471
    472472        bitmap_initialize(&zones.info[z1].bitmap, zones.info[z1].count,
    473473            confdata + (sizeof(frame_t) * zones.info[z1].count));
    474474        bitmap_clear_range(&zones.info[z1].bitmap, 0, zones.info[z1].count);
    475        
     475
    476476        zones.info[z1].frames = (frame_t *) confdata;
    477        
     477
    478478        /*
    479479         * Copy frames and bits from both zones to preserve parents, etc.
    480480         */
    481        
     481
    482482        for (size_t i = 0; i < old_z1->count; i++) {
    483483                bitmap_set(&zones.info[z1].bitmap, i,
     
    485485                zones.info[z1].frames[i] = old_z1->frames[i];
    486486        }
    487        
     487
    488488        for (size_t i = 0; i < zones.info[z2].count; i++) {
    489489                bitmap_set(&zones.info[z1].bitmap, base_diff + i,
     
    510510{
    511511        assert(zones.info[znum].flags & ZONE_AVAILABLE);
    512        
     512
    513513        size_t cframes = SIZE2FRAMES(zone_conf_size(count));
    514        
     514
    515515        if ((pfn < zones.info[znum].base) ||
    516516            (pfn >= zones.info[znum].base + zones.info[znum].count))
    517517                return;
    518        
     518
    519519        for (size_t i = 0; i < cframes; i++)
    520520                (void) zone_frame_free(&zones.info[znum],
     
    536536{
    537537        irq_spinlock_lock(&zones.lock, true);
    538        
     538
    539539        bool ret = true;
    540        
     540
    541541        /*
    542542         * We can join only 2 zones with none existing inbetween,
     
    549549                goto errout;
    550550        }
    551        
     551
    552552        pfn_t cframes = SIZE2FRAMES(zone_conf_size(
    553553            zones.info[z2].base - zones.info[z1].base
    554554            + zones.info[z2].count));
    555        
     555
    556556        /* Allocate merged zone data inside one of the zones */
    557557        pfn_t pfn;
     
    566566                goto errout;
    567567        }
    568        
     568
    569569        /* Preserve original data from z1 */
    570570        zone_t old_z1 = zones.info[z1];
    571        
     571
    572572        /* Do zone merging */
    573573        zone_merge_internal(z1, z2, &old_z1, (void *) PA2KA(PFN2ADDR(pfn)));
    574        
     574
    575575        /* Subtract zone information from busy frames */
    576576        zones.info[z1].busy_count -= cframes;
    577        
     577
    578578        /* Free old zone information */
    579579        return_config_frames(z1,
     
    582582            ADDR2PFN(KA2PA((uintptr_t) zones.info[z2].frames)),
    583583            zones.info[z2].count);
    584        
     584
    585585        /* Move zones down */
    586586        for (size_t i = z2 + 1; i < zones.count; i++)
    587587                zones.info[i - 1] = zones.info[i];
    588        
     588
    589589        zones.count--;
    590        
     590
    591591errout:
    592592        irq_spinlock_unlock(&zones.lock, true);
    593        
     593
    594594        return ret;
    595595}
     
    605605{
    606606        size_t i = 1;
    607        
     607
    608608        while (i < zones.count) {
    609609                if (!zone_merge(i - 1, i))
     
    631631        zone->free_count = count;
    632632        zone->busy_count = 0;
    633        
     633
    634634        if (flags & ZONE_AVAILABLE) {
    635635                /*
     
    637637                 * frame_t structures in the configuration space).
    638638                 */
    639                
     639
    640640                bitmap_initialize(&zone->bitmap, count, confdata +
    641641                    (sizeof(frame_t) * count));
    642642                bitmap_clear_range(&zone->bitmap, 0, count);
    643                
     643
    644644                /*
    645645                 * Initialize the array of frame_t structures.
    646646                 */
    647                
     647
    648648                zone->frames = (frame_t *) confdata;
    649                
     649
    650650                for (size_t i = 0; i < count; i++)
    651651                        frame_initialize(&zone->frames[i]);
     
    672672{
    673673        size_t frames = SIZE2FRAMES(zone_conf_size(count));
    674        
     674
    675675        return ADDR2PFN((uintptr_t)
    676676            frame_alloc(frames, FRAME_LOWMEM | FRAME_ATOMIC, 0));
     
    697697{
    698698        irq_spinlock_lock(&zones.lock, true);
    699        
     699
    700700        if (flags & ZONE_AVAILABLE) {  /* Create available zone */
    701701                /*
     
    705705                 */
    706706                assert(confframe != ADDR2PFN((uintptr_t ) NULL));
    707                
     707
    708708                /* Update the known end of physical memory. */
    709709                config.physmem_end = max(config.physmem_end, PFN2ADDR(start + count));
    710                
     710
    711711                /*
    712712                 * If confframe is supposed to be inside our zone, then make sure
     
    714714                 */
    715715                size_t confcount = SIZE2FRAMES(zone_conf_size(count));
    716                
     716
    717717                if ((confframe >= start) && (confframe < start + count)) {
    718718                        for (; confframe < start + count; confframe++) {
     
    721721                                    KA2PA(config.base), config.kernel_size))
    722722                                        continue;
    723                                
     723
    724724                                if (overlaps(addr, PFN2ADDR(confcount),
    725725                                    KA2PA(config.stack_base), config.stack_size))
    726726                                        continue;
    727                                
     727
    728728                                bool overlap = false;
    729729                                for (size_t i = 0; i < init.cnt; i++) {
     
    735735                                        }
    736736                                }
    737                                
     737
    738738                                if (overlap)
    739739                                        continue;
    740                                
     740
    741741                                break;
    742742                        }
    743                        
     743
    744744                        if (confframe >= start + count)
    745745                                panic("Cannot find configuration data for zone.");
    746746                }
    747                
     747
    748748                size_t znum = zones_insert_zone(start, count, flags);
    749749                if (znum == (size_t) -1) {
     
    751751                        return (size_t) -1;
    752752                }
    753                
     753
    754754                void *confdata = (void *) PA2KA(PFN2ADDR(confframe));
    755755                zone_construct(&zones.info[znum], start, count, flags, confdata);
    756                
     756
    757757                /* If confdata in zone, mark as unavailable */
    758758                if ((confframe >= start) && (confframe < start + count)) {
     
    761761                                    i - zones.info[znum].base);
    762762                }
    763                
     763
    764764                irq_spinlock_unlock(&zones.lock, true);
    765                
     765
    766766                return znum;
    767767        }
    768        
     768
    769769        /* Non-available zone */
    770770        size_t znum = zones_insert_zone(start, count, flags);
     
    773773                return (size_t) -1;
    774774        }
    775        
     775
    776776        zone_construct(&zones.info[znum], start, count, flags, NULL);
    777        
     777
    778778        irq_spinlock_unlock(&zones.lock, true);
    779        
     779
    780780        return znum;
    781781}
     
    789789{
    790790        irq_spinlock_lock(&zones.lock, true);
    791        
     791
    792792        size_t znum = find_zone(pfn, 1, hint);
    793        
     793
    794794        assert(znum != (size_t) -1);
    795        
     795
    796796        zone_get_frame(&zones.info[znum],
    797797            pfn - zones.info[znum].base)->parent = data;
    798        
     798
    799799        irq_spinlock_unlock(&zones.lock, true);
    800800}
     
    803803{
    804804        irq_spinlock_lock(&zones.lock, true);
    805        
     805
    806806        size_t znum = find_zone(pfn, 1, hint);
    807        
     807
    808808        assert(znum != (size_t) -1);
    809        
     809
    810810        void *res = zone_get_frame(&zones.info[znum],
    811811            pfn - zones.info[znum].base)->parent;
    812        
     812
    813813        irq_spinlock_unlock(&zones.lock, true);
    814        
     814
    815815        return res;
    816816}
     
    831831{
    832832        assert(count > 0);
    833        
     833
    834834        size_t hint = pzone ? (*pzone) : 0;
    835835        pfn_t frame_constraint = ADDR2PFN(constraint);
    836        
     836
    837837        /*
    838838         * If not told otherwise, we must first reserve the memory.
     
    840840        if (!(flags & FRAME_NO_RESERVE))
    841841                reserve_force_alloc(count);
    842        
     842
    843843loop:
    844844        irq_spinlock_lock(&zones.lock, true);
    845        
     845
    846846        /*
    847847         * First, find suitable frame zone.
     
    849849        size_t znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags),
    850850            frame_constraint, hint);
    851        
     851
    852852        /*
    853853         * If no memory, reclaim some slab memory,
     
    858858                size_t freed = slab_reclaim(0);
    859859                irq_spinlock_lock(&zones.lock, true);
    860                
     860
    861861                if (freed > 0)
    862862                        znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags),
    863863                            frame_constraint, hint);
    864                
     864
    865865                if (znum == (size_t) -1) {
    866866                        irq_spinlock_unlock(&zones.lock, true);
    867867                        freed = slab_reclaim(SLAB_RECLAIM_ALL);
    868868                        irq_spinlock_lock(&zones.lock, true);
    869                        
     869
    870870                        if (freed > 0)
    871871                                znum = find_free_zone(count, FRAME_TO_ZONE_FLAGS(flags),
     
    873873                }
    874874        }
    875        
     875
    876876        if (znum == (size_t) -1) {
    877877                if (flags & FRAME_ATOMIC) {
    878878                        irq_spinlock_unlock(&zones.lock, true);
    879                        
     879
    880880                        if (!(flags & FRAME_NO_RESERVE))
    881881                                reserve_free(count);
    882                        
     882
    883883                        return 0;
    884884                }
    885                
     885
    886886                size_t avail = frame_total_free_get_internal();
    887                
     887
    888888                irq_spinlock_unlock(&zones.lock, true);
    889                
     889
    890890                if (!THREAD)
    891891                        panic("Cannot wait for %zu frames to become available "
    892892                            "(%zu available).", count, avail);
    893                
     893
    894894                /*
    895895                 * Sleep until some frames are available again.
    896896                 */
    897                
     897
    898898#ifdef CONFIG_DEBUG
    899899                log(LF_OTHER, LVL_DEBUG,
     
    901901                    "%zu available.", THREAD->tid, count, avail);
    902902#endif
    903                
     903
    904904                /*
    905905                 * Since the mem_avail_mtx is an active mutex, we need to
     
    908908                ipl_t ipl = interrupts_disable();
    909909                mutex_lock(&mem_avail_mtx);
    910                
     910
    911911                if (mem_avail_req > 0)
    912912                        mem_avail_req = min(mem_avail_req, count);
    913913                else
    914914                        mem_avail_req = count;
    915                
     915
    916916                size_t gen = mem_avail_gen;
    917                
     917
    918918                while (gen == mem_avail_gen)
    919919                        condvar_wait(&mem_avail_cv, &mem_avail_mtx);
    920                
     920
    921921                mutex_unlock(&mem_avail_mtx);
    922922                interrupts_restore(ipl);
    923                
     923
    924924#ifdef CONFIG_DEBUG
    925925                log(LF_OTHER, LVL_DEBUG, "Thread %" PRIu64 " woken up.",
    926926                    THREAD->tid);
    927927#endif
    928                
     928
    929929                goto loop;
    930930        }
    931        
     931
    932932        pfn_t pfn = zone_frame_alloc(&zones.info[znum], count,
    933933            frame_constraint) + zones.info[znum].base;
    934        
     934
    935935        irq_spinlock_unlock(&zones.lock, true);
    936        
     936
    937937        if (pzone)
    938938                *pzone = znum;
    939        
     939
    940940        return PFN2ADDR(pfn);
    941941}
     
    960960{
    961961        size_t freed = 0;
    962        
     962
    963963        irq_spinlock_lock(&zones.lock, true);
    964        
     964
    965965        for (size_t i = 0; i < count; i++) {
    966966                /*
     
    969969                pfn_t pfn = ADDR2PFN(start) + i;
    970970                size_t znum = find_zone(pfn, 1, 0);
    971                
     971
    972972                assert(znum != (size_t) -1);
    973                
     973
    974974                freed += zone_frame_free(&zones.info[znum],
    975975                    pfn - zones.info[znum].base);
    976976        }
    977        
     977
    978978        irq_spinlock_unlock(&zones.lock, true);
    979        
     979
    980980        /*
    981981         * Signal that some memory has been freed.
     
    984984         * with TLB shootdown.
    985985         */
    986        
     986
    987987        ipl_t ipl = interrupts_disable();
    988988        mutex_lock(&mem_avail_mtx);
    989        
     989
    990990        if (mem_avail_req > 0)
    991991                mem_avail_req -= min(mem_avail_req, freed);
    992        
     992
    993993        if (mem_avail_req == 0) {
    994994                mem_avail_gen++;
    995995                condvar_broadcast(&mem_avail_cv);
    996996        }
    997        
     997
    998998        mutex_unlock(&mem_avail_mtx);
    999999        interrupts_restore(ipl);
    1000        
     1000
    10011001        if (!(flags & FRAME_NO_RESERVE))
    10021002                reserve_free(freed);
     
    10241024{
    10251025        irq_spinlock_lock(&zones.lock, true);
    1026        
     1026
    10271027        /*
    10281028         * First, find host frame zone for addr.
    10291029         */
    10301030        size_t znum = find_zone(pfn, 1, 0);
    1031        
     1031
    10321032        assert(znum != (size_t) -1);
    1033        
     1033
    10341034        zones.info[znum].frames[pfn - zones.info[znum].base].refcount++;
    1035        
     1035
    10361036        irq_spinlock_unlock(&zones.lock, true);
    10371037}
     
    10431043{
    10441044        irq_spinlock_lock(&zones.lock, true);
    1045        
     1045
    10461046        for (size_t i = 0; i < count; i++) {
    10471047                size_t znum = find_zone(start + i, 1, 0);
    1048                
     1048
    10491049                if (znum == (size_t) -1)  /* PFN not found */
    10501050                        continue;
    1051                
     1051
    10521052                zone_mark_unavailable(&zones.info[znum],
    10531053                    start + i - zones.info[znum].base);
    10541054        }
    1055        
     1055
    10561056        irq_spinlock_unlock(&zones.lock, true);
    10571057}
     
    10681068                condvar_initialize(&mem_avail_cv);
    10691069        }
    1070        
     1070
    10711071        /* Tell the architecture to create some memory */
    10721072        frame_low_arch_init();
    1073        
     1073
    10741074        if (config.cpu_active == 1) {
    10751075                frame_mark_unavailable(ADDR2PFN(KA2PA(config.base)),
     
    10771077                frame_mark_unavailable(ADDR2PFN(KA2PA(config.stack_base)),
    10781078                    SIZE2FRAMES(config.stack_size));
    1079                
     1079
    10801080                for (size_t i = 0; i < init.cnt; i++)
    10811081                        frame_mark_unavailable(ADDR2PFN(init.tasks[i].paddr),
    10821082                            SIZE2FRAMES(init.tasks[i].size));
    1083                
     1083
    10841084                if (ballocs.size)
    10851085                        frame_mark_unavailable(ADDR2PFN(KA2PA(ballocs.base)),
    10861086                            SIZE2FRAMES(ballocs.size));
    1087                
     1087
    10881088                /*
    10891089                 * Blacklist first frame, as allocating NULL would
     
    10921092                frame_mark_unavailable(0, 1);
    10931093        }
    1094        
     1094
    10951095        frame_high_arch_init();
    10961096}
     
    11131113{
    11141114        uintptr_t limit = KA2PA(config.identity_base) + config.identity_size;
    1115        
     1115
    11161116        if (low) {
    11171117                if (*basep > limit)
    11181118                        return false;
    1119                
     1119
    11201120                if (*basep + *sizep > limit)
    11211121                        *sizep = limit - *basep;
     
    11231123                if (*basep + *sizep <= limit)
    11241124                        return false;
    1125                
     1125
    11261126                if (*basep <= limit) {
    11271127                        *sizep -= limit - *basep;
     
    11291129                }
    11301130        }
    1131        
     1131
    11321132        return true;
    11331133}
     
    11391139{
    11401140        irq_spinlock_lock(&zones.lock, true);
    1141        
     1141
    11421142        uint64_t total = 0;
    1143        
     1143
    11441144        for (size_t i = 0; i < zones.count; i++)
    11451145                total += (uint64_t) FRAMES2SIZE(zones.info[i].count);
    1146        
     1146
    11471147        irq_spinlock_unlock(&zones.lock, true);
    1148        
     1148
    11491149        return total;
    11501150}
     
    11571157        assert(busy != NULL);
    11581158        assert(free != NULL);
    1159        
     1159
    11601160        irq_spinlock_lock(&zones.lock, true);
    1161        
     1161
    11621162        *total = 0;
    11631163        *unavail = 0;
    11641164        *busy = 0;
    11651165        *free = 0;
    1166        
     1166
    11671167        for (size_t i = 0; i < zones.count; i++) {
    11681168                *total += (uint64_t) FRAMES2SIZE(zones.info[i].count);
    1169                
     1169
    11701170                if (zones.info[i].flags & ZONE_AVAILABLE) {
    11711171                        *busy += (uint64_t) FRAMES2SIZE(zones.info[i].busy_count);
     
    11741174                        *unavail += (uint64_t) FRAMES2SIZE(zones.info[i].count);
    11751175        }
    1176        
     1176
    11771177        irq_spinlock_unlock(&zones.lock, true);
    11781178}
     
    11901190        printf("[nr] [base address    ] [frames    ] [flags ] [free frames ] [busy frames ]\n");
    11911191#endif
    1192        
     1192
    11931193        /*
    11941194         * Because printing may require allocation of memory, we may not hold
     
    12011201         * the listing).
    12021202         */
    1203        
     1203
    12041204        size_t free_lowmem = 0;
    12051205        size_t free_highmem = 0;
    12061206        size_t free_highprio = 0;
    1207        
     1207
    12081208        for (size_t i = 0;; i++) {
    12091209                irq_spinlock_lock(&zones.lock, true);
    1210                
     1210
    12111211                if (i >= zones.count) {
    12121212                        irq_spinlock_unlock(&zones.lock, true);
    12131213                        break;
    12141214                }
    1215                
     1215
    12161216                pfn_t fbase = zones.info[i].base;
    12171217                uintptr_t base = PFN2ADDR(fbase);
     
    12201220                size_t free_count = zones.info[i].free_count;
    12211221                size_t busy_count = zones.info[i].busy_count;
    1222                
     1222
    12231223                bool available = ((flags & ZONE_AVAILABLE) != 0);
    12241224                bool lowmem = ((flags & ZONE_LOWMEM) != 0);
    12251225                bool highmem = ((flags & ZONE_HIGHMEM) != 0);
    12261226                bool highprio = is_high_priority(fbase, count);
    1227                
     1227
    12281228                if (available) {
    12291229                        if (lowmem)
    12301230                                free_lowmem += free_count;
    1231                        
     1231
    12321232                        if (highmem)
    12331233                                free_highmem += free_count;
    1234                        
     1234
    12351235                        if (highprio) {
    12361236                                free_highprio += free_count;
     
    12411241                                 * statistics.
    12421242                                 */
    1243                                
     1243
    12441244                                for (size_t index = 0; index < count; index++) {
    12451245                                        if (is_high_priority(fbase + index, 0)) {
     
    12511251                        }
    12521252                }
    1253                
     1253
    12541254                irq_spinlock_unlock(&zones.lock, true);
    1255                
     1255
    12561256                printf("%-4zu", i);
    1257                
     1257
    12581258#ifdef __32_BITS__
    12591259                printf("  %p", (void *) base);
    12601260#endif
    1261                
     1261
    12621262#ifdef __64_BITS__
    12631263                printf(" %p", (void *) base);
    12641264#endif
    1265                
     1265
    12661266                printf(" %12zu %c%c%c%c%c    ", count,
    12671267                    available ? 'A' : '-',
     
    12701270                    (flags & ZONE_LOWMEM) ? 'L' : '-',
    12711271                    (flags & ZONE_HIGHMEM) ? 'H' : '-');
    1272                
     1272
    12731273                if (available)
    12741274                        printf("%14zu %14zu",
    12751275                            free_count, busy_count);
    1276                
     1276
    12771277                printf("\n");
    12781278        }
    1279        
     1279
    12801280        printf("\n");
    1281        
     1281
    12821282        uint64_t size;
    12831283        const char *size_suffix;
    1284        
     1284
    12851285        bin_order_suffix(FRAMES2SIZE(free_lowmem), &size, &size_suffix,
    12861286            false);
    12871287        printf("Available low memory:    %zu frames (%" PRIu64 " %s)\n",
    12881288            free_lowmem, size, size_suffix);
    1289        
     1289
    12901290        bin_order_suffix(FRAMES2SIZE(free_highmem), &size, &size_suffix,
    12911291            false);
    12921292        printf("Available high memory:   %zu frames (%" PRIu64 " %s)\n",
    12931293            free_highmem, size, size_suffix);
    1294        
     1294
    12951295        bin_order_suffix(FRAMES2SIZE(free_highprio), &size, &size_suffix,
    12961296            false);
     
    13081308        irq_spinlock_lock(&zones.lock, true);
    13091309        size_t znum = (size_t) -1;
    1310        
     1310
    13111311        for (size_t i = 0; i < zones.count; i++) {
    13121312                if ((i == num) || (PFN2ADDR(zones.info[i].base) == num)) {
     
    13151315                }
    13161316        }
    1317        
     1317
    13181318        if (znum == (size_t) -1) {
    13191319                irq_spinlock_unlock(&zones.lock, true);
     
    13211321                return;
    13221322        }
    1323        
     1323
    13241324        size_t free_lowmem = 0;
    13251325        size_t free_highmem = 0;
    13261326        size_t free_highprio = 0;
    1327        
     1327
    13281328        pfn_t fbase = zones.info[znum].base;
    13291329        uintptr_t base = PFN2ADDR(fbase);
     
    13321332        size_t free_count = zones.info[znum].free_count;
    13331333        size_t busy_count = zones.info[znum].busy_count;
    1334        
     1334
    13351335        bool available = ((flags & ZONE_AVAILABLE) != 0);
    13361336        bool lowmem = ((flags & ZONE_LOWMEM) != 0);
    13371337        bool highmem = ((flags & ZONE_HIGHMEM) != 0);
    13381338        bool highprio = is_high_priority(fbase, count);
    1339        
     1339
    13401340        if (available) {
    13411341                if (lowmem)
    13421342                        free_lowmem = free_count;
    1343                
     1343
    13441344                if (highmem)
    13451345                        free_highmem = free_count;
    1346                
     1346
    13471347                if (highprio) {
    13481348                        free_highprio = free_count;
     
    13531353                         * statistics.
    13541354                         */
    1355                        
     1355
    13561356                        for (size_t index = 0; index < count; index++) {
    13571357                                if (is_high_priority(fbase + index, 0)) {
     
    13631363                }
    13641364        }
    1365        
     1365
    13661366        irq_spinlock_unlock(&zones.lock, true);
    1367        
     1367
    13681368        uint64_t size;
    13691369        const char *size_suffix;
    1370        
     1370
    13711371        bin_order_suffix(FRAMES2SIZE(count), &size, &size_suffix, false);
    1372        
     1372
    13731373        printf("Zone number:             %zu\n", znum);
    13741374        printf("Zone base address:       %p\n", (void *) base);
     
    13811381            (flags & ZONE_LOWMEM) ? 'L' : '-',
    13821382            (flags & ZONE_HIGHMEM) ? 'H' : '-');
    1383        
     1383
    13841384        if (available) {
    13851385                bin_order_suffix(FRAMES2SIZE(busy_count), &size, &size_suffix,
     
    13871387                printf("Allocated space:         %zu frames (%" PRIu64 " %s)\n",
    13881388                    busy_count, size, size_suffix);
    1389                
     1389
    13901390                bin_order_suffix(FRAMES2SIZE(free_count), &size, &size_suffix,
    13911391                    false);
    13921392                printf("Available space:         %zu frames (%" PRIu64 " %s)\n",
    13931393                    free_count, size, size_suffix);
    1394                
     1394
    13951395                bin_order_suffix(FRAMES2SIZE(free_lowmem), &size, &size_suffix,
    13961396                    false);
    13971397                printf("Available low memory:    %zu frames (%" PRIu64 " %s)\n",
    13981398                    free_lowmem, size, size_suffix);
    1399                
     1399
    14001400                bin_order_suffix(FRAMES2SIZE(free_highmem), &size, &size_suffix,
    14011401                    false);
    14021402                printf("Available high memory:   %zu frames (%" PRIu64 " %s)\n",
    14031403                    free_highmem, size, size_suffix);
    1404                
     1404
    14051405                bin_order_suffix(FRAMES2SIZE(free_highprio), &size, &size_suffix,
    14061406                    false);
Note: See TracChangeset for help on using the changeset viewer.